#include <define.h>

//#define NAME                    SCRIPT_

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



procedure start;
#include <push.h>
procedure combat;
procedure critter_p_proc;
procedure pickup_p_proc;
procedure talk_p_proc;
procedure destroy_p_proc;
procedure look_at_p_proc;
procedure damage_p_proc;
procedure FryDialog;
procedure FryCombat;
procedure FryEnd;
procedure Fry00;
procedure Fry01;
procedure Fry02;
procedure Fry03;
procedure Fry04;
procedure Fry05;
procedure Fry06;
procedure Fry07;
procedure Fry08;
procedure Fry09;
procedure Fry10;
procedure Fry11;
procedure Fry12;
procedure Fry13;
procedure Fry14;
procedure Fry15;
procedure Fry16;
procedure Fry17;
procedure Fry18;
procedure Fry19;
procedure Fry20;
procedure Fry21;
procedure Fry22;
procedure Fry23;
procedure Fry24;

variable hostile1;
variable Only_Once := 1;

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;
		if (global_var(GVAR_FRY_DEAD) == 1) then begin
			set_obj_visibility(self_obj, 1);
		end
		critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_TEAM_NUM, 40);
		critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_AI_PACKET, AI_HUB_POLICE);
	end
	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
			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
				end
			end
		end
	end
end

procedure combat
begin
	hostile1 := 1;
end

procedure critter_p_proc
begin
	if (hostile1) then begin
		hostile1 := 0;
		attack_complex(dude_obj, 0, 1, 0, 0, 30000, 0, 0);
	end
	if ((game_time_hour >= 600) and (game_time_hour < 700) or ((game_time_hour >= 700) and (game_time_hour < 1800))) then begin
		if (tile_num(self_obj) != 21508) then begin
			animate_move_obj_to_tile(self_obj, 21508, ANIMATE_WALK);
		end
		else begin
			if (random(1, 150) == 1) then begin
				animate_move_obj_to_tile(self_obj, tile_num_in_direction(tile_num(self_obj), random(0, 5), random(3, 5)), ANIMATE_WALK);
			end
		end
	end
	else begin
		if (tile_num(self_obj) != 22280) then begin
			animate_move_obj_to_tile(self_obj, 22280, ANIMATE_WALK);
		end
	end
end

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

procedure talk_p_proc
begin
	call Get_Reaction;
	call FryDialog;
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_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
	set_global_var(GVAR_FRY_DEAD, 1);
end

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

procedure damage_p_proc
begin
	variable LVar0 := 0;
	LVar0 := obj_pid(source_obj);
	if (party_member_obj(LVar0) != 0) then begin
		set_global_var(GVAR_ENEMY_HUB, 1);
	end
end

procedure FryDialog
begin
	if ((game_time_hour >= 1800) and (game_time_hour < 1900) or ((game_time_hour >= 1900) or (game_time_hour < 600))) then begin
		float_msg(self_obj, message_str(SCRIPT_FRY, 146), FLOAT_MSG_GREEN);
	end
	else begin
		start_gdialog(SCRIPT_FRY, self_obj, 4, -1, -1);
		gsay_start;
		if (global_var(GVAR_WANTED_FOR_MURDER) > 2) then begin
			call Fry11;
		end
		else begin
			if (global_var(GVAR_GREENE_DEAD) == 1) then begin
				call Fry12;
			end
			else begin
				if (global_var(GVAR_WANTED_THEFT) > 2) then begin
					call Fry13;
				end
				else begin
					if (local_var(4) == 0) then begin
						call Fry00;
						set_local_var(4, 1);
					end
					else begin
						if (global_var(GVAR_CHILDKILLER_REPUTATION) > 2) then begin
							call Fry10;
						end
						else begin
							if (local_var(1) == 3) then begin
								call Fry14;
							end
							else begin
								if (local_var(1) == 2) then begin
									call Fry15;
								end
								else begin
									call Fry16;
								end
							end
						end
					end
				end
			end
		end
		gsay_end;
		end_dialogue;
	end
end

procedure FryCombat
begin
	hostile1 := 1;
end

procedure FryEnd
begin
end

procedure Fry00
begin
	if (global_var(GVAR_CHILDKILLER_REPUTATION) > 2) then begin
		gsay_reply(SCRIPT_FRY, 101);
	end
	else begin
		gsay_reply(SCRIPT_FRY, 102);
	end
	giq_option(4, SCRIPT_FRY, 103, Fry01, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_FRY, 104, FryEnd, NEUTRAL_REACTION);
	giq_option(-3, SCRIPT_FRY, 105, Fry09, NEUTRAL_REACTION);
	giq_option(-3, SCRIPT_FRY, 106, Fry09, NEUTRAL_REACTION);
end

procedure Fry01
begin
	gsay_reply(SCRIPT_FRY, 107);
	giq_option(4, SCRIPT_FRY, 108, Fry02, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_FRY, 109, Fry03, NEUTRAL_REACTION);
end

procedure Fry02
begin
	set_global_var(GVAR_DECKER_KNOWN, 1);
	gsay_reply(SCRIPT_FRY, 110);
	if (global_var(GVAR_MISSING_CARAVAN) != 2) then begin
		set_global_var(GVAR_MISSING_CARAVAN, 1);
	end
	call Fry05;
end

procedure Fry03
begin
	set_global_var(GVAR_DECKER_KNOWN, 1);
	gsay_reply(SCRIPT_FRY, 111);
	if (global_var(GVAR_MISSING_CARAVAN) != 2) then begin
		set_global_var(GVAR_MISSING_CARAVAN, 1);
	end
	giq_option(4, SCRIPT_FRY, 112, Fry07, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_FRY, 113, Fry04, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_FRY, 114, Fry06, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_FRY, 115, Fry21, NEUTRAL_REACTION);
	if (global_var(GVAR_FIND_WATER_CHIP) != 2) then begin
		giq_option(4, SCRIPT_FRY, 147, Fry23, NEUTRAL_REACTION);
	end
	giq_option(4, SCRIPT_FRY, 116, Fry08, NEUTRAL_REACTION);
end

procedure Fry04
begin
	gsay_reply(SCRIPT_FRY, 117);
	call Fry05;
end

procedure Fry05
begin
	if (global_var(GVAR_DECKER_KNOWN) == 1) then begin
		giq_option(4, SCRIPT_FRY, 112, Fry07, NEUTRAL_REACTION);
	end
	if (global_var(GVAR_MISSING_CARAVAN) == 1) then begin
		giq_option(4, SCRIPT_FRY, 114, Fry06, NEUTRAL_REACTION);
	end
	giq_option(4, SCRIPT_FRY, 115, Fry21, NEUTRAL_REACTION);
	if (global_var(GVAR_FIND_WATER_CHIP) != 2) then begin
		giq_option(4, SCRIPT_FRY, 147, Fry23, NEUTRAL_REACTION);
	end
	giq_option(4, SCRIPT_FRY, 116, Fry08, NEUTRAL_REACTION);
end

procedure Fry06
begin
	gsay_reply(SCRIPT_FRY, 118);
	call Fry05;
end

procedure Fry07
begin
	gsay_reply(SCRIPT_FRY, 119);
	call Fry05;
end

procedure Fry08
begin
	gsay_message(SCRIPT_FRY, 120, NEUTRAL_REACTION);
	call FryEnd;
end

procedure Fry09
begin
	gsay_message(SCRIPT_FRY, 121, NEUTRAL_REACTION);
	call FryEnd;
end

procedure Fry10
begin
	gsay_message(SCRIPT_FRY, 122, NEUTRAL_REACTION);
	call FryEnd;
end

procedure Fry11
begin
	gsay_message(SCRIPT_FRY, 123, NEUTRAL_REACTION);
	call FryCombat;
end

procedure Fry12
begin
	gsay_message(SCRIPT_FRY, 124, NEUTRAL_REACTION);
	call FryEnd;
end

procedure Fry13
begin
	gsay_reply(SCRIPT_FRY, 125);
	call FryCombat;
end

procedure Fry14
begin
	if (dude_is_male) then begin
		gsay_reply(SCRIPT_FRY, 130);
	end
	else begin
		gsay_reply(SCRIPT_FRY, 131);
	end
	call Fry17;
end

procedure Fry15
begin
	gsay_reply(SCRIPT_FRY, 132);
	call Fry17;
end

procedure Fry16
begin
	gsay_reply(SCRIPT_FRY, 133);
	call Fry17;
end

procedure Fry17
begin
	if (global_var(GVAR_FIND_WATER_CHIP) != 2) then begin
		giq_option(4, SCRIPT_FRY, 147, Fry24, NEUTRAL_REACTION);
	end
	giq_option(4, SCRIPT_FRY, 134, Fry18, GOOD_REACTION);
	giq_option(4, SCRIPT_FRY, 135, Fry19, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_FRY, 136, Fry20, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_FRY, 137, Fry21, GOOD_REACTION);
	giq_option(4, SCRIPT_FRY, 138, FryEnd, NEUTRAL_REACTION);
	giq_option(-3, SCRIPT_FRY, 139, Fry09, NEUTRAL_REACTION);
	giq_option(-3, SCRIPT_FRY, 140, Fry09, NEUTRAL_REACTION);
end

procedure Fry18
begin
	gsay_reply(SCRIPT_FRY, 141);
	call Fry17;
end

procedure Fry19
begin
	gsay_reply(SCRIPT_FRY, 142);
	call Fry17;
end

procedure Fry20
begin
	gsay_reply(SCRIPT_FRY, 143);
	call Fry17;
end

procedure Fry21
begin
	gsay_reply(SCRIPT_FRY, 144);
	call Fry17;
end

procedure Fry22
begin
	gsay_message(SCRIPT_FRY, 145, NEUTRAL_REACTION);
	call FryEnd;
end

procedure Fry23
begin
	gsay_reply(SCRIPT_FRY, 148);
	call Fry05;
end

procedure Fry24
begin
	gsay_reply(SCRIPT_FRY, 148);
	call Fry17;
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