#include <define.h>

//#define NAME                    SCRIPT_

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



procedure start;
#include <push.h>
procedure do_dialogue;
procedure pre_dialogue;
procedure Darrel01;
procedure Darrel02;
procedure Darrel02a;
procedure Darrel02b;
procedure Darrel02c;
procedure Darrel03;
procedure Darrel04;
procedure Darrel05;
procedure Darrel06;
procedure Darrel07;
procedure Darrel08;
procedure Darrel09;
procedure Darrel10;
procedure Darrel11;
procedure Darrel12;
procedure Darrel13;
procedure Darrel14;
procedure Darrel15;
procedure Darrel16;
procedure Darrel58;
procedure Darrel59;
procedure Darrel60;
procedure Darrel61;
procedure Darrel62;
procedure Darrel63;
procedure Darrel64;
procedure Darrel66;
procedure Darrel67;
procedure Darrel68;
procedure Darrel69;
procedure Darrel70;
procedure Darrel71;
procedure Darrel72;
procedure Darrel73;
procedure Darrel75;
procedure Darrel76;
procedure DarrelEnd;
procedure giveradx;
procedure combat;
procedure damage_p_proc;
procedure critter_p_proc;
procedure pickup_p_proc;
procedure talk_p_proc;
procedure destroy_p_proc;
procedure look_at_p_proc;

variable known;
variable only_once := 1;
variable hostile1;
variable radx;
variable second;
variable ccount;

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;
		critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_TEAM_NUM, 44);
		critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_AI_PACKET, AI_BROTHERHOOD_KNIGHT);
	end
	if (script_action == look_at_proc) then begin
		call look_at_p_proc;
	end
	else begin
		if (script_action == damage_proc) then begin
			call damage_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
end

procedure do_dialogue
begin
	call Get_Reaction;
	start_gdialog(SCRIPT_DARREL, self_obj, 4, -1, -1);
	gsay_start;
	if (global_var(GVAR_BECOME_AN_INITIATE) == 1) then begin
		if (second) then begin
			call Darrel71;
		end
		else begin
			second := 1;
			call Darrel59;
		end
	end
	else begin
		if (local_var(4) == 0) then begin
			call Darrel01;
		end
		else begin
			call Darrel16;
		end
	end
	gsay_end;
	end_dialogue;
	set_local_var(4, 1);
end

procedure pre_dialogue
begin
	if (local_var(4) == 0) then begin
		call do_dialogue;
	end
	else begin
		if (global_var(GVAR_BECOME_AN_INITIATE) == 2) then begin
			call Darrel73;
		end
		else begin
			call do_dialogue;
		end
	end
end

procedure Darrel01
begin
	gsay_reply(SCRIPT_DARREL, 102);
	giq_option(-3, SCRIPT_DARREL, 103, Darrel02, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DARREL, 104, Darrel03, NEUTRAL_REACTION);
	if (global_var(GVAR_NECROP_WATER_CHIP_TAKEN) != 1) then begin
		giq_option(4, SCRIPT_DARREL, 105, Darrel04, NEUTRAL_REACTION);
	end
	if (global_var(GVAR_MISSING_CARAVAN) == 1) then begin
		giq_option(4, SCRIPT_DARREL, 106, Darrel75, NEUTRAL_REACTION);
	end
	giq_option(4, SCRIPT_DARREL, 107, DarrelEnd, NEUTRAL_REACTION);
end

procedure Darrel02
begin
	if (local_var(6) == 0) then begin
		gsay_reply(SCRIPT_DARREL, 108);
		giq_option(-3, SCRIPT_DARREL, 300, Darrel02a, NEUTRAL_REACTION);
	end
	else begin
		gsay_message(SCRIPT_DARREL, 108, NEUTRAL_REACTION);
	end
end

procedure Darrel02a
begin
	gsay_reply(SCRIPT_DARREL, 209);
	giq_option(-3, SCRIPT_DARREL, 300, Darrel02b, NEUTRAL_REACTION);
end

procedure Darrel02b
begin
	gsay_reply(SCRIPT_DARREL, 210);
	giq_option(-3, SCRIPT_DARREL, 300, Darrel02c, NEUTRAL_REACTION);
end

procedure Darrel02c
begin
	gsay_reply(SCRIPT_DARREL, 211);
	giq_option(-3, SCRIPT_DARREL, 300, giveradx, NEUTRAL_REACTION);
end

procedure Darrel03
begin
	gsay_reply(SCRIPT_DARREL, 110);
	giq_option(4, SCRIPT_DARREL, 111, Darrel05, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DARREL, 112, Darrel12, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DARREL, 113, Darrel06, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DARREL, 114, DarrelEnd, NEUTRAL_REACTION);
end

procedure Darrel04
begin
	gsay_reply(SCRIPT_DARREL, 115);
	giq_option(4, SCRIPT_DARREL, 116, Darrel07, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DARREL, 201, DarrelEnd, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DARREL, 118, Darrel11, NEUTRAL_REACTION);
end

procedure Darrel05
begin
	gsay_reply(SCRIPT_DARREL, 119);
	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
		giq_option(4, SCRIPT_DARREL, 120, DarrelEnd, NEUTRAL_REACTION);
	end
	giq_option(4, SCRIPT_DARREL, 121, Darrel08, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DARREL, 122, Darrel09, NEUTRAL_REACTION);
end

procedure Darrel06
begin
	gsay_reply(SCRIPT_DARREL, 123);
	giq_option(4, SCRIPT_DARREL, 202, DarrelEnd, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DARREL, 125, Darrel04, NEUTRAL_REACTION);
end

procedure Darrel07
begin
	gsay_reply(SCRIPT_DARREL, 126);
	giq_option(4, SCRIPT_DARREL, 202, DarrelEnd, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DARREL, 127, Darrel03, NEUTRAL_REACTION);
end

procedure Darrel08
begin
	gsay_reply(SCRIPT_DARREL, 128);
	giq_option(4, SCRIPT_DARREL, 129, Darrel10, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DARREL, 130, Darrel11, NEUTRAL_REACTION);
end

procedure Darrel09
begin
	gsay_reply(SCRIPT_DARREL, 109);
	giq_option(4, SCRIPT_DARREL, 129, Darrel10, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DARREL, 130, Darrel11, NEUTRAL_REACTION);
end

procedure Darrel10
begin
	gsay_reply(SCRIPT_DARREL, 131);
	giq_option(4, SCRIPT_DARREL, 132, Darrel07, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DARREL, 133, Darrel11, NEUTRAL_REACTION);
end

procedure Darrel11
begin
	gsay_message(SCRIPT_DARREL, 134, NEUTRAL_REACTION);
end

procedure Darrel12
begin
	gsay_reply(SCRIPT_DARREL, 135);
	giq_option(4, SCRIPT_DARREL, 136, Darrel13, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DARREL, 137, Darrel15, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DARREL, 203, DarrelEnd, NEUTRAL_REACTION);
end

procedure Darrel13
begin
	gsay_reply(SCRIPT_DARREL, 139);
	giq_option(4, SCRIPT_DARREL, 140, Darrel13, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DARREL, 132, Darrel07, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DARREL, 204, DarrelEnd, NEUTRAL_REACTION);
end

procedure Darrel14
begin
	gsay_reply(SCRIPT_DARREL, 143);
	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
		giq_option(4, SCRIPT_DARREL, 144, combat, BAD_REACTION);
	end
	giq_option(4, SCRIPT_DARREL, 141, Darrel07, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DARREL, 145, DarrelEnd, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DARREL, 146, Darrel05, NEUTRAL_REACTION);
end

procedure Darrel15
begin
	gsay_reply(SCRIPT_DARREL, 147);
	giq_option(4, SCRIPT_DARREL, 148, Darrel14, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DARREL, 149, Darrel07, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DARREL, 203, DarrelEnd, NEUTRAL_REACTION);
end

procedure Darrel16
begin
	float_msg(self_obj, message_str(SCRIPT_DARREL, 151), FLOAT_MSG_RED);
end

procedure Darrel58
begin
	set_local_var(5, 1);
	if (dude_is_male) then begin
		float_msg(self_obj, message_str(SCRIPT_DARREL, 152), FLOAT_MSG_RED);
	end
	else begin
		float_msg(self_obj, message_str(SCRIPT_DARREL, 153), FLOAT_MSG_RED);
	end
end

procedure Darrel59
begin
	gsay_reply(SCRIPT_DARREL, 154);
	giq_option(4, SCRIPT_DARREL, 155, Darrel60, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DARREL, 156, Darrel61, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DARREL, 157, Darrel62, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DARREL, 158, DarrelEnd, NEUTRAL_REACTION);
	giq_option(-3, SCRIPT_DARREL, 103, Darrel02, NEUTRAL_REACTION);
end

procedure Darrel60
begin
	gsay_reply(SCRIPT_DARREL, 159);
	giq_option(4, SCRIPT_DARREL, 160, Darrel63, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DARREL, 161, Darrel63, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DARREL, 162, Darrel64, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DARREL, 163, Darrel61, NEUTRAL_REACTION);
end

procedure Darrel61
begin
	gsay_reply(SCRIPT_DARREL, 164);
	giq_option(4, SCRIPT_DARREL, 165, Darrel66, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DARREL, 166, Darrel67, NEUTRAL_REACTION);
end

procedure Darrel62
begin
	gsay_message(SCRIPT_DARREL, 167, NEUTRAL_REACTION);
end

procedure Darrel63
begin
	gsay_reply(SCRIPT_DARREL, 168);
	giq_option(4, SCRIPT_DARREL, 203, DarrelEnd, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DARREL, 170, Darrel72, NEUTRAL_REACTION);
end

procedure Darrel64
begin
	gsay_reply(SCRIPT_DARREL, 171);
	giq_option(4, SCRIPT_DARREL, 205, DarrelEnd, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DARREL, 170, Darrel69, NEUTRAL_REACTION);
end

procedure Darrel66
begin
	gsay_reply(SCRIPT_DARREL, 174);
	giq_option(4, SCRIPT_DARREL, 175, Darrel68, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DARREL, 176, DarrelEnd, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DARREL, 177, Darrel63, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DARREL, 206, DarrelEnd, NEUTRAL_REACTION);
end

procedure Darrel67
begin
	gsay_reply(SCRIPT_DARREL, 179);
	giq_option(4, SCRIPT_DARREL, 180, Darrel64, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DARREL, 203, DarrelEnd, NEUTRAL_REACTION);
end

procedure Darrel68
begin
	gsay_reply(SCRIPT_DARREL, 181);
	giq_option(4, SCRIPT_DARREL, 182, DarrelEnd, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DARREL, 183, Darrel63, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DARREL, 184, DarrelEnd, NEUTRAL_REACTION);
end

procedure Darrel69
begin
	gsay_reply(SCRIPT_DARREL, 189);
	giq_option(4, SCRIPT_DARREL, 203, DarrelEnd, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DARREL, 190, Darrel72, NEUTRAL_REACTION);
end

procedure Darrel70
begin
	gsay_reply(SCRIPT_DARREL, 168);
	giq_option(4, SCRIPT_DARREL, 203, DarrelEnd, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DARREL, 190, Darrel72, NEUTRAL_REACTION);
end

procedure Darrel71
begin
	gsay_reply(SCRIPT_DARREL, 191);
	giq_option(4, SCRIPT_DARREL, 188, Darrel72, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DARREL, 192, DarrelEnd, NEUTRAL_REACTION);
	giq_option(-3, SCRIPT_DARREL, 103, Darrel02, NEUTRAL_REACTION);
end

procedure Darrel72
begin
	gsay_reply(SCRIPT_DARREL, 193);
	giq_option(4, SCRIPT_DARREL, 186, Darrel69, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DARREL, 187, Darrel70, NEUTRAL_REACTION);
	if (global_var(GVAR_MISSING_CARAVAN) == 1) then begin
		giq_option(4, SCRIPT_DARREL, 106, Darrel75, NEUTRAL_REACTION);
	end
	giq_option(4, SCRIPT_DARREL, 207, DarrelEnd, NEUTRAL_REACTION);
end

procedure Darrel73
begin
	ccount := ccount + 1;
	if (ccount < 6) then begin
		float_msg(self_obj, message_str(SCRIPT_RD1SCRB1, 200 + random(0, 2)), FLOAT_MSG_RED);
	end
	else begin
		if (ccount < 9) then begin
			float_msg(self_obj, message_str(SCRIPT_RD1SCRB1, 203 + random(0, 4)), FLOAT_MSG_RED);
		end
		else begin
			if (ccount < 12) then begin
				float_msg(self_obj, message_str(SCRIPT_RD1SCRB1, 209 + random(0, 3)), FLOAT_MSG_RED);
			end
			else begin
				display_msg(message_str(SCRIPT_RD1SCRB1, 213));
			end
		end
	end
end

procedure Darrel75
begin
	gsay_reply(SCRIPT_DARREL, 195);
	giq_option(4, SCRIPT_DARREL, 196, Darrel11, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DARREL, 197, Darrel76, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DARREL, 104, Darrel03, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DARREL, 198, DarrelEnd, NEUTRAL_REACTION);
end

procedure Darrel76
begin
	gsay_reply(SCRIPT_DARREL, 199);
	giq_option(4, SCRIPT_DARREL, 104, Darrel03, NEUTRAL_REACTION);
	if (global_var(GVAR_NECROP_WATER_CHIP_TAKEN) != 1) then begin
		giq_option(4, SCRIPT_DARREL, 105, Darrel04, NEUTRAL_REACTION);
	end
	giq_option(4, SCRIPT_DARREL, 208, DarrelEnd, NEUTRAL_REACTION);
end

procedure DarrelEnd
begin
end

procedure giveradx
begin
	set_local_var(6, 1);
	radx := create_object_sid(109, 0, 0, -1);
	add_obj_to_inven(dude_obj, radx);
	gsay_reply(SCRIPT_DARREL, 212);
	giq_option(-3, SCRIPT_DARREL, 300, DarrelEnd, NEUTRAL_REACTION);
end

procedure combat
begin
	hostile1 := 1;
end

procedure damage_p_proc
begin
	set_global_var(GVAR_ENEMY_BROTHERHOOD, 1);
end

procedure critter_p_proc
begin
	if (global_var(GVAR_ENEMY_BROTHERHOOD)) then begin
		hostile1 := 1;
	end
	if (tile_distance_objs(self_obj, dude_obj) > 12) then begin
		hostile1 := 0;
	end
	if (hostile1) then begin
		set_global_var(GVAR_ENEMY_BROTHERHOOD, 1);
		hostile1 := 0;
		attack_complex(dude_obj, 0, 1, 0, 0, 30000, 0, 0);
	end
	if (local_var(5) == 0) then begin
		if (global_var(GVAR_BECOME_AN_INITIATE) == 1) then begin
			call Darrel58;
		end
	end
end

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

procedure talk_p_proc
begin
	if (global_var(GVAR_BECOME_AN_INITIATE) == 5) then begin
		float_msg(self_obj, message_str(SCRIPT_CABBOT, 233), FLOAT_MSG_RED);
	end
	else begin
		call pre_dialogue;
	end
end

procedure destroy_p_proc
begin
	set_global_var(GVAR_ENEMY_BROTHERHOOD, 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

procedure look_at_p_proc
begin
	script_overrides;
	if (known) then begin
		display_msg(message_str(SCRIPT_DARREL, 100));
	end
	else begin
		display_msg(message_str(SCRIPT_DARREL, 101));
	end
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