#include <define.h>

//#define NAME                    SCRIPT_

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


variable GVar0 := 1;
variable GVar1;

procedure start;
#include <push.h>
procedure look_at_p_proc;
procedure description_p_proc;
procedure talk_p_proc;
procedure damage_p_proc;
procedure destroy_p_proc;
procedure critter_p_proc;
procedure pickup_p_proc;
procedure Gab01;
procedure Gab02;
procedure Gab03;
procedure Gab04;
procedure Gab05;
procedure Gab06;
procedure Gab07;
procedure Gab08;
procedure Gab09;
procedure Gab09a;
procedure Gab11;
procedure Gab12;
procedure Gab13;
procedure Gab14;
procedure Gab15;
procedure Gab16;
procedure Gab17;
procedure Gab18;
procedure Gab19;
procedure Gab20;
procedure Gab21;
procedure Gab22;
procedure Gab23;
procedure Gab24;
procedure Gab25;
procedure Gab26;
procedure Gab27;
procedure Gab28;
procedure GabBarter;
procedure GabEnd;
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;


procedure Start
begin
	if (GVar0) then begin
		if (obj_is_carrying_obj_pid(self_obj, 41) == 0) then begin
			item_caps_adjust(self_obj, random(50, 150));
		end
		critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_TEAM_NUM, 48);
		critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_AI_PACKET, AI_GUNRUNNERS);
		GVar0 := 0;
	end
end

procedure look_at_p_proc
begin
	script_overrides;
	if (local_var(4) == 1) then begin
		display_msg(message_str(SCRIPT_GABRIEL, 101));
	end
	else begin
		display_msg(message_str(SCRIPT_GABRIEL, 100));
	end
end

procedure description_p_proc
begin
	script_overrides;
	if (local_var(4) == 1) then begin
		display_msg(message_str(SCRIPT_GABRIEL, 101));
	end
	else begin
		display_msg(message_str(SCRIPT_GABRIEL, 100));
	end
end

procedure talk_p_proc
begin
	if (global_var(GVAR_ENEMY_BLADE) == 1) then begin
		float_msg(self_obj, message_str(SCRIPT_ENEMY, random(100, 105)), FLOAT_MSG_RED);
	end
	else begin
		call Get_Reaction;
		start_gdialog(SCRIPT_GABRIEL, self_obj, 4, -1, -1);
		gsay_start;
		if (local_var(4) == 0) then begin
			if (global_var(GVAR_WATER_CHIP_8) == 9250) then begin
				call Gab17;
			end
			else begin
				call Gab01;
			end
		end
		else begin
			if (local_var(5) == 1) then begin
				if ((local_var(8) == 0) and (global_var(GVAR_BLADES) == 2)) then begin
					set_local_var(8, 1);
					call Gab25;
				end
				else begin
					call Gab27;
				end
			end
			else begin
				if ((global_var(GVAR_GUN_RUNNER) == 9201) and (global_var(GVAR_WATER_CHIP_8) == 9250)) then begin
					call Gab20;
				end
				else begin
					if (global_var(GVAR_GUN_RUNNER) == 9201) then begin
						call Gab13;
					end
					else begin
						if ((local_var(6) == 1) or (local_var(7) == 1)) then begin
							call Gab24;
						end
						else begin
							call Gab12;
						end
					end
				end
			end
		end
		gsay_end;
		end_dialogue;
	end
end

procedure damage_p_proc
begin
	if (source_obj == dude_obj) then begin
		set_global_var(GVAR_ENEMY_BLADE, 1);
	end
end

procedure destroy_p_proc
begin
	if (source_obj == dude_obj) then begin
		set_global_var(GVAR_ENEMY_BLADE, 1);
		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
end

procedure critter_p_proc
begin
	if (obj_can_see_obj(self_obj, dude_obj)) then begin
		if (global_var(GVAR_ENEMY_BLADE) == 1) then begin
			attack_complex(dude_obj, 0, 1, 0, 0, 30000, 0, 0);
		end
	end
end

procedure pickup_p_proc
begin
	set_global_var(GVAR_ENEMY_BLADE, 1);
end

procedure Gab01
begin
	gsay_reply(SCRIPT_GABRIEL, 102);
	gsay_option(SCRIPT_GABRIEL, 103, Gab02, NEUTRAL_REACTION);
	gsay_option(SCRIPT_GABRIEL, 104, Gab04, NEUTRAL_REACTION);
end

procedure Gab02
begin
	gsay_reply(SCRIPT_GABRIEL, 105);
	gsay_option(SCRIPT_GABRIEL, 106, Gab03, NEUTRAL_REACTION);
	set_local_var(4, 1);
end

procedure Gab03
begin
	gsay_reply(SCRIPT_GABRIEL, 107);
	gsay_option(SCRIPT_GABRIEL, 108, Gab08, NEUTRAL_REACTION);
end

procedure Gab04
begin
	gsay_reply(SCRIPT_GABRIEL, 109);
	gsay_option(SCRIPT_GABRIEL, 110, Gab05, NEUTRAL_REACTION);
end

procedure Gab05
begin
	gsay_reply(SCRIPT_GABRIEL, 111);
	gsay_option(SCRIPT_GABRIEL, 112, Gab06, NEUTRAL_REACTION);
end

procedure Gab06
begin
	gsay_reply(SCRIPT_GABRIEL, 113);
	if (global_var(GVAR_WATER_CHIP_8) == 9250) then begin
		gsay_option(SCRIPT_GABRIEL, 114, Gab19, NEUTRAL_REACTION);
	end
	else begin
		gsay_option(SCRIPT_GABRIEL, 114, Gab07, NEUTRAL_REACTION);
	end
	gsay_option(SCRIPT_GABRIEL, 115, Gab08, NEUTRAL_REACTION);
end

procedure Gab07
begin
	gsay_reply(SCRIPT_GABRIEL, 116);
	gsay_option(SCRIPT_GABRIEL, 117, Gab03, NEUTRAL_REACTION);
end

procedure Gab08
begin
	gsay_reply(SCRIPT_GABRIEL, 118);
	gsay_option(SCRIPT_GABRIEL, 119, Gab09, NEUTRAL_REACTION);
	if (global_var(GVAR_BLADES) == 9101) then begin
		if (dude_is_male) then begin
			gsay_option(SCRIPT_GABRIEL, 170, Gab11, NEUTRAL_REACTION);
		end
		else begin
			gsay_option(SCRIPT_GABRIEL, 171, Gab11, NEUTRAL_REACTION);
		end
	end
end

procedure Gab09
begin
	gsay_reply(SCRIPT_GABRIEL, 121);
	gsay_option(SCRIPT_GABRIEL, 122, Gab09a, NEUTRAL_REACTION);
	gsay_option(SCRIPT_GABRIEL, 123, GabEnd, NEUTRAL_REACTION);
	gsay_option(SCRIPT_GABRIEL, 124, Gab11, NEUTRAL_REACTION);
end

procedure Gab09a
begin
	set_global_var(GVAR_GUN_RUNNER, 9201);
end

procedure Gab11
begin
	gsay_reply(SCRIPT_GABRIEL, 125);
	gsay_option(SCRIPT_GABRIEL, 126, Gab09a, NEUTRAL_REACTION);
	gsay_option(SCRIPT_GABRIEL, 127, GabEnd, NEUTRAL_REACTION);
end

procedure Gab12
begin
	gsay_reply(SCRIPT_GABRIEL, 128);
	gsay_option(SCRIPT_GABRIEL, 129, Gab04, NEUTRAL_REACTION);
	gsay_option(SCRIPT_GABRIEL, 130, GabEnd, NEUTRAL_REACTION);
end

procedure Gab13
begin
	if (dude_is_male) then begin
		gsay_reply(SCRIPT_GABRIEL, 172);
	end
	else begin
		gsay_reply(SCRIPT_GABRIEL, 173);
	end
	gsay_option(SCRIPT_GABRIEL, 132, Gab15, NEUTRAL_REACTION);
	gsay_option(SCRIPT_GABRIEL, 133, Gab14, NEUTRAL_REACTION);
end

procedure Gab14
begin
	gsay_reply(SCRIPT_GABRIEL, 134);
	gsay_option(SCRIPT_GABRIEL, 135, GabEnd, NEUTRAL_REACTION);
end

procedure Gab15
begin
	gsay_reply(SCRIPT_GABRIEL, 136);
	gsay_option(SCRIPT_GABRIEL, 137, GabEnd, NEUTRAL_REACTION);
end

procedure Gab16
begin
	gsay_reply(SCRIPT_GABRIEL, 138);
	gsay_option(SCRIPT_GABRIEL, 139, GabEnd, NEUTRAL_REACTION);
end

procedure Gab17
begin
	gsay_reply(SCRIPT_GABRIEL, 140);
	gsay_option(SCRIPT_GABRIEL, 141, Gab18, NEUTRAL_REACTION);
	gsay_option(SCRIPT_GABRIEL, 142, Gab04, NEUTRAL_REACTION);
end

procedure Gab18
begin
	gsay_reply(SCRIPT_GABRIEL, 143);
	gsay_option(SCRIPT_GABRIEL, 144, Gab20, NEUTRAL_REACTION);
	set_local_var(4, 1);
end

procedure Gab19
begin
	gsay_reply(SCRIPT_GABRIEL, 145);
	gsay_option(SCRIPT_GABRIEL, 146, Gab20, NEUTRAL_REACTION);
end

procedure Gab20
begin
	if (dude_is_male) then begin
		gsay_reply(SCRIPT_GABRIEL, 174);
	end
	else begin
		gsay_reply(SCRIPT_GABRIEL, 175);
	end
	gsay_option(SCRIPT_GABRIEL, 148, Gab21, NEUTRAL_REACTION);
	if (global_var(GVAR_BLADES) == 9101) then begin
		if (dude_is_male) then begin
			gsay_option(SCRIPT_GABRIEL, 170, Gab22, NEUTRAL_REACTION);
		end
		else begin
			gsay_option(SCRIPT_GABRIEL, 171, Gab22, NEUTRAL_REACTION);
		end
	end
	gsay_option(SCRIPT_GABRIEL, 150, Gab23, NEUTRAL_REACTION);
end

procedure Gab21
begin
	gsay_reply(SCRIPT_GABRIEL, 151);
	if (dude_is_male) then begin
		gsay_option(SCRIPT_GABRIEL, 176, GabEnd, NEUTRAL_REACTION);
	end
	else begin
		gsay_option(SCRIPT_GABRIEL, 177, GabEnd, NEUTRAL_REACTION);
	end
	if (global_var(GVAR_WATER_CHIP_8) != 2) then begin
		set_global_var(GVAR_WATER_CHIP_8, 2);
		set_global_var(GVAR_PLAYER_REPUTATION, global_var(GVAR_PLAYER_REPUTATION) + 1);
		give_exp_points(1000);
		display_msg(message_str(SCRIPT_GENCHAT, 103) + 1000 + message_str(SCRIPT_GENCHAT, 104));
		set_local_var(6, 1);
	end
end

procedure Gab22
begin
	if (dude_is_male) then begin
		gsay_reply(SCRIPT_GABRIEL, 178);
	end
	else begin
		gsay_reply(SCRIPT_GABRIEL, 179);
	end
	gsay_option(SCRIPT_GABRIEL, 154, GabEnd, NEUTRAL_REACTION);
	if (global_var(GVAR_GUN_RUNNER) != 9202) then begin
		set_global_var(GVAR_GUN_RUNNER, 9202);
		set_global_var(GVAR_PLAYER_REPUTATION, global_var(GVAR_PLAYER_REPUTATION) + 1);
		give_exp_points(1000);
		display_msg(message_str(SCRIPT_GENCHAT, 103) + 1000 + message_str(SCRIPT_GENCHAT, 104));
		set_local_var(5, 1);
	end
end

procedure Gab23
begin
	if (dude_is_male) then begin
		gsay_reply(SCRIPT_GABRIEL, 180);
	end
	else begin
		gsay_reply(SCRIPT_GABRIEL, 181);
	end
	gsay_option(SCRIPT_GABRIEL, 156, GabEnd, NEUTRAL_REACTION);
	call Up_React_Level;
end

procedure Gab24
begin
	if (dude_is_male) then begin
		gsay_message(SCRIPT_GABRIEL, 182, NEUTRAL_REACTION);
	end
	else begin
		gsay_message(SCRIPT_GABRIEL, 183, NEUTRAL_REACTION);
	end
end

procedure Gab25
begin
	if (dude_is_male) then begin
		gsay_reply(SCRIPT_GABRIEL, 184);
	end
	else begin
		gsay_reply(SCRIPT_GABRIEL, 185);
	end
	gsay_option(SCRIPT_GABRIEL, 159, Gab26, NEUTRAL_REACTION);
	gsay_option(SCRIPT_GABRIEL, 160, GabBarter, NEUTRAL_REACTION);
	gsay_option(SCRIPT_GABRIEL, 161, GabEnd, NEUTRAL_REACTION);
end

procedure Gab26
begin
	if (dude_is_male) then begin
		gsay_reply(SCRIPT_GABRIEL, 186);
	end
	else begin
		gsay_reply(SCRIPT_GABRIEL, 187);
	end
	gsay_option(SCRIPT_GABRIEL, 163, GabBarter, NEUTRAL_REACTION);
	gsay_option(SCRIPT_GABRIEL, 164, GabEnd, NEUTRAL_REACTION);
end

procedure Gab27
begin
	if (dude_is_male) then begin
		gsay_reply(SCRIPT_GABRIEL, 184);
	end
	else begin
		gsay_reply(SCRIPT_GABRIEL, 185);
	end
	gsay_option(SCRIPT_GABRIEL, 166, GabBarter, NEUTRAL_REACTION);
	gsay_option(SCRIPT_GABRIEL, 167, GabEnd, NEUTRAL_REACTION);
end

procedure Gab28
begin
	gsay_message(SCRIPT_GABRIEL, 168, NEUTRAL_REACTION);
end

procedure GabBarter
begin
	gsay_message(SCRIPT_GABRIEL, 188, NEUTRAL_REACTION);
end

procedure GabEnd
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
	GVar1 := message_str(SCRIPT_MODREACT, random(100, 105));
end