#include <define.h>

//#define NAME                    SCRIPT_

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



procedure start;
#include <push.h>
procedure damage_p_proc;
procedure destroy_p_proc;
procedure look_at_p_proc;
procedure pickup_p_proc;
procedure talk_p_proc;
procedure critter_p_proc;
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 hostile1;
variable initialized1;


procedure start
begin
	if (not(initialized1)) then begin
		if ((global_var(GVAR_BLADES) == 9103) or (global_var(GVAR_BLADES) == 9102)) then begin
			critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_TEAM_NUM, 0);
		end
		else begin
			critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_TEAM_NUM, 49);
		end
		initialized1 := 1;
	end
	else begin
		if (script_action == destroy_proc) then begin
			call destroy_p_proc;
		end
		else begin
			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
				end
			end
		end
	end
end

procedure damage_p_proc
begin
	if (source_obj == dude_obj) then begin
		set_global_var(GVAR_ENEMY_ADYTUM, 1);
		critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_TEAM_NUM, 49);
	end
end

procedure destroy_p_proc
begin
	if (source_obj == dude_obj) then begin
		set_global_var(GVAR_ENEMY_ADYTUM, 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
		critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_TEAM_NUM, 49);
	end
end

procedure look_at_p_proc
begin
	script_overrides;
	if (local_var(0)) then begin
		display_msg(message_str(SCRIPT_LORRI, 100));
	end
	else begin
		display_msg(message_str(SCRIPT_LORRI, 101));
	end
end

procedure pickup_p_proc
begin
	set_global_var(GVAR_ENEMY_ADYTUM, 1);
end

procedure talk_p_proc
begin
	start_gdialog(SCRIPT_LORRI, self_obj, 4, -1, -1);
	gsay_start;
	if (local_var(0)) then begin
		call Lorri04;
	end
	else begin
		call Lorri01;
	end
	gsay_end;
	end_dialogue;
end

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

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

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

procedure Lorri03
begin
	set_local_var(0, 1);
	gsay_reply(SCRIPT_LORRI, 113);
	giq_option(4, SCRIPT_LORRI, 114, Lorri02, NEUTRAL_REACTION);
end

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

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

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

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

procedure Lorri08
begin
	gsay_reply(SCRIPT_LORRI, message_str(SCRIPT_LORRI, 128));
	giq_option(4, SCRIPT_LORRI, 131, Lorri02, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_LORRI, 132, Lorri05, NEUTRAL_REACTION);
end

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

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

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

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

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

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

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

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

procedure Lorri17
begin
	gsay_reply(SCRIPT_LORRI, message_str(SCRIPT_LORRI, 156) + message_str(SCRIPT_LORRI, 157));
	giq_option(4, SCRIPT_LORRI, 158, Lorri18, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_LORRI, 159, Lorri08, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_LORRI, 160, Lorri19, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_LORRI, 162, Lorri05, NEUTRAL_REACTION);
end

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

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

procedure Lorri20
begin
	gsay_reply(SCRIPT_LORRI, 170);
	giq_option(4, SCRIPT_LORRI, 171, Lorri21, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_LORRI, 172, Lorri22, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_LORRI, 173, Lorri23, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_LORRI, 174, Lorri24, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_LORRI, 175, Lorri25, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_LORRI, 176, Lorri05, NEUTRAL_REACTION);
end

procedure Lorri21
begin
	gsay_reply(SCRIPT_LORRI, 177);
	call Lorri26;
end

procedure Lorri22
begin
	gsay_reply(SCRIPT_LORRI, 178);
	call Lorri26;
end

procedure Lorri23
begin
	gsay_reply(SCRIPT_LORRI, 179);
	call Lorri26;
end

procedure Lorri24
begin
	gsay_reply(SCRIPT_LORRI, 180);
	call Lorri26;
end

procedure Lorri25
begin
	gsay_reply(SCRIPT_LORRI, 181);
	call Lorri26;
end

procedure Lorri26
begin
	giq_option(4, SCRIPT_LORRI, 182, Lorri20, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_LORRI, 183, Lorri02, NEUTRAL_REACTION);
end

procedure Lorri27
begin
	gsay_message(SCRIPT_LORRI, 184, NEUTRAL_REACTION);
end