#include <define.h>

//#define NAME                    SCRIPT_

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



procedure start;
#include <push.h>
procedure farli0;
procedure farli1;
procedure farli2;
procedure farli3;
procedure farli4;

variable Herebefore;


procedure start
begin
	if ((script_action == look_at_proc) or (script_action == description_proc)) then begin
		script_overrides;
		display_msg(message_str(SCRIPT_FARLI, 100));
	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_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
		else begin
			if (script_action == talk_proc) then begin
				script_overrides;
				if (Herebefore > 1) then begin
					call farli4;
				end
				else begin
					if (Herebefore == 1) then begin
						Herebefore := Herebefore + 1;
						call farli3;
					end
					else begin
						Herebefore := Herebefore + 1;
						start_gdialog(SCRIPT_FARLI, self_obj, 4, -1, -1);
						gsay_start;
						call farli0;
						gsay_end;
						end_dialogue;
					end
				end
			end
		end
	end
end

procedure farli0
begin
	gsay_reply(SCRIPT_FARLI, 101);
	giq_option(3, SCRIPT_FARLI, 102, farli1, NEUTRAL_REACTION);
end

procedure farli1
begin
	gsay_reply(SCRIPT_FARLI, 103);
	giq_option(3, SCRIPT_FARLI, message_str(SCRIPT_FARLI, 104) + proto_data(obj_pid(dude_obj), 1) + message_str(SCRIPT_FARLI, 105), farli2, NEUTRAL_REACTION);
end

procedure farli2
begin
	variable LVar0 := 0;
	gsay_message(SCRIPT_FARLI, 106, NEUTRAL_REACTION);
	LVar0 := create_object_sid(95, 0, 0, -1);
	add_obj_to_inven(dude_obj, LVar0);
end

procedure farli3
begin
	float_msg(self_obj, message_str(SCRIPT_FARLI, 107), FLOAT_MSG_NORMAL);
end

procedure farli4
begin
	float_msg(self_obj, message_str(SCRIPT_FARLI, 108), FLOAT_MSG_NORMAL);
end