#include <define.h>

//#define NAME                    SCRIPT_

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



procedure start;
#include <push.h>
procedure do_dialogue;
procedure Lorri01;
procedure Lorri02;
procedure Lorri03;
procedure Lorri04;
procedure Lorri05;
procedure Lorri06;
procedure Lorri07;
procedure Lorri08;
procedure Lorri09;
procedure Lorri10;
procedure Lorri11;
procedure Lorri12;
procedure Lorri13;
procedure Lorri14;
procedure Lorri15;
procedure Lorri16;
procedure Lorri17;
procedure Lorri18;
procedure Lorri19;
procedure Lorri20;
procedure Lorri21;
procedure Lorri22;
procedure Lorri23;
procedure Lorri24;
procedure Lorri25;
procedure Lorri26;
procedure Lorri27;

variable known;
variable line21flag;
variable line22flag;
variable line23flag;
variable line24flag;
variable line25flag;

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 (script_action == talk_proc) then begin
		call do_dialogue;
	end
	else begin
		if ((script_action == look_at_proc) or (script_action == description_proc)) then begin
			script_overrides;
			if (not(known)) then begin
				display_msg(message_str(0, 100));
			end
			else begin
				display_msg(message_str(0, 101));
			end
		end
		else begin
			if (script_action == timed_event_proc) then begin
				attack_complex(dude_obj, 0, 1, 0, 0, 30000, 0, 0);
			end
		end
	end
end

procedure do_dialogue
begin
	start_gdialog(-1, self_obj, 4, -1, -1);
	gsay_start;
	if (known) then begin
		call Lorri04;
	end
	else begin
		call Lorri01;
	end
	gsay_end;
	end_dialogue;
end

procedure Lorri01
begin
	gsay_reply(0, 102);
	giq_option(4, 0, 103, Lorri02, NEUTRAL_REACTION);
	giq_option(4, 0, message_str(0, 104) + proto_data(obj_pid(dude_obj), 1) + message_str(0, 105), Lorri03, NEUTRAL_REACTION);
	giq_option(-3, 0, message_str(0, 106), Lorri15, NEUTRAL_REACTION);
end

procedure Lorri02
begin
	gsay_reply(0, 107);
	if (not(known)) then begin
		giq_option(4, 0, 108, Lorri03, NEUTRAL_REACTION);
	end
	giq_option(4, 0, 109, Lorri16, NEUTRAL_REACTION);
	giq_option(4, 0, 110, Lorri20, NEUTRAL_REACTION);
	giq_option(4, 0, 111, Lorri04, NEUTRAL_REACTION);
	giq_option(4, 0, 112, Lorri05, NEUTRAL_REACTION);
end

procedure Lorri03
begin
	known := 1;
	gsay_reply(0, 113);
	giq_option(4, 0, 114, Lorri02, NEUTRAL_REACTION);
	call Goodbyes;
	giq_option(4, 0, exit_line, Lorri05, NEUTRAL_REACTION);
end

procedure Lorri04
begin
	gsay_reply(0, 115);
	giq_option(4, 0, 116, Lorri06, NEUTRAL_REACTION);
	giq_option(4, 0, 117, Lorri07, NEUTRAL_REACTION);
	giq_option(4, 0, 118, Lorri02, NEUTRAL_REACTION);
end

procedure Lorri05
begin
	gsay_message(0, 119, NEUTRAL_REACTION);
end

procedure Lorri06
begin
	gsay_reply(0, 120);
	giq_option(4, 0, 121, Lorri08, NEUTRAL_REACTION);
	giq_option(4, 0, 122, Lorri10, NEUTRAL_REACTION);
	giq_option(4, 0, 123, Lorri02, NEUTRAL_REACTION);
	giq_option(4, 0, 124, Lorri05, NEUTRAL_REACTION);
end

procedure Lorri07
begin
	gsay_reply(0, 125);
	giq_option(4, 0, 126, Lorri02, NEUTRAL_REACTION);
	giq_option(4, 0, 127, Lorri05, NEUTRAL_REACTION);
end

procedure Lorri08
begin
	gsay_message(0, 128, NEUTRAL_REACTION);
	gsay_reply(0, 129);
	giq_option(4, 0, 130, Lorri09, NEUTRAL_REACTION);
	giq_option(4, 0, 131, Lorri02, NEUTRAL_REACTION);
	giq_option(4, 0, 132, Lorri05, NEUTRAL_REACTION);
end

procedure Lorri09
begin
	gsay_reply(0, 133);
	giq_option(4, 0, 134, Lorri12, NEUTRAL_REACTION);
	giq_option(4, 0, 135, Lorri02, NEUTRAL_REACTION);
	giq_option(4, 0, 136, Lorri05, NEUTRAL_REACTION);
end

procedure Lorri10
begin
	gsay_reply(0, 137);
	giq_option(4, 0, 138, Lorri11, NEUTRAL_REACTION);
	giq_option(4, 0, 139, Lorri06, NEUTRAL_REACTION);
	giq_option(4, 0, 140, Lorri02, NEUTRAL_REACTION);
	giq_option(4, 0, message_str(0, 141), Lorri05, NEUTRAL_REACTION);
end

procedure Lorri11
begin
	gsay_reply(0, 142);
	giq_option(4, 0, 143, Lorri13, NEUTRAL_REACTION);
	giq_option(4, 0, 144, Lorri14, NEUTRAL_REACTION);
	giq_option(4, 0, 145, Lorri02, NEUTRAL_REACTION);
	giq_option(4, 0, 146, Lorri05, NEUTRAL_REACTION);
end

procedure Lorri12
begin
	gsay_message(0, 147, NEUTRAL_REACTION);
end

procedure Lorri13
begin
	gsay_message(0, 148, NEUTRAL_REACTION);
end

procedure Lorri14
begin
	gsay_reply(0, 149);
	giq_option(4, 0, message_str(0, 150), Lorri02, NEUTRAL_REACTION);
	giq_option(4, 0, 151, Lorri05, NEUTRAL_REACTION);
end

procedure Lorri15
begin
	gsay_message(0, 152, NEUTRAL_REACTION);
end

procedure Lorri16
begin
	gsay_reply(0, 153);
	giq_option(4, 0, 154, Lorri17, NEUTRAL_REACTION);
	giq_option(4, 0, 155, Lorri05, NEUTRAL_REACTION);
end

procedure Lorri17
begin
	gsay_message(0, 156, NEUTRAL_REACTION);
	gsay_reply(0, 157);
	giq_option(4, 0, 158, Lorri18, NEUTRAL_REACTION);
	giq_option(4, 0, 159, Lorri08, NEUTRAL_REACTION);
	giq_option(4, 0, 160, Lorri19, NEUTRAL_REACTION);
	giq_option(4, 0, 161, Lorri27, NEUTRAL_REACTION);
	giq_option(4, 0, 162, Lorri05, NEUTRAL_REACTION);
end

procedure Lorri18
begin
	gsay_reply(0, 163);
	giq_option(4, 0, 164, Lorri02, NEUTRAL_REACTION);
	giq_option(4, 0, 165, Lorri05, NEUTRAL_REACTION);
end

procedure Lorri19
begin
	gsay_reply(0, 166);
	giq_option(4, 0, 167, Lorri08, NEUTRAL_REACTION);
	giq_option(4, 0, 168, Lorri02, NEUTRAL_REACTION);
	giq_option(4, 0, 169, Lorri05, NEUTRAL_REACTION);
end

procedure Lorri20
begin
	gsay_reply(0, 170);
	if (not(line21flag)) then begin
		giq_option(4, 0, 171, Lorri21, NEUTRAL_REACTION);
	end
	if (not(line22flag)) then begin
		giq_option(4, 0, 172, Lorri22, NEUTRAL_REACTION);
	end
	if (not(line23flag)) then begin
		giq_option(4, 0, 173, Lorri23, NEUTRAL_REACTION);
	end
	if (not(line24flag)) then begin
		giq_option(4, 0, 174, Lorri24, NEUTRAL_REACTION);
	end
	if (not(line25flag)) then begin
		giq_option(4, 0, 175, Lorri25, NEUTRAL_REACTION);
	end
	giq_option(4, 0, 176, Lorri05, NEUTRAL_REACTION);
end

procedure Lorri21
begin
	gsay_reply(0, 177);
	line21flag := 1;
	call Lorri26;
end

procedure Lorri22
begin
	gsay_reply(0, 178);
	line22flag := 1;
	call Lorri26;
end

procedure Lorri23
begin
	gsay_reply(0, 179);
	line23flag := 1;
	call Lorri26;
end

procedure Lorri24
begin
	gsay_reply(0, 180);
	line24flag := 1;
	call Lorri26;
end

procedure Lorri25
begin
	gsay_reply(0, 181);
	line25flag := 1;
	call Lorri26;
end

procedure Lorri26
begin
	giq_option(4, 0, 182, Lorri20, NEUTRAL_REACTION);
	giq_option(4, 0, 183, Lorri02, NEUTRAL_REACTION);
	call Goodbyes;
	giq_option(4, 0, exit_line, Lorri05, NEUTRAL_REACTION);
end

procedure Lorri27
begin
	gsay_message(0, 184, NEUTRAL_REACTION);
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