#include <define.h>

//#define NAME                    SCRIPT_

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



procedure start;
#include <push.h>
procedure critter_p_proc;
procedure destroy_p_proc;
procedure talk_p_proc;
procedure Brenden01;
procedure Brenden02;
procedure Brenden03;
procedure Brenden04;
procedure Brenden05;
procedure Brenden06;
procedure Brenden07;
procedure Brenden08;
procedure Brenden09;
procedure Brenden10;
procedure Brenden11;
procedure Brenden12;
procedure BrendenEnd;

variable hostile1;
variable initialized1;


procedure start
begin
	if (not(initialized1)) then begin
		critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_TEAM_NUM, 44);
		critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_AI_PACKET, AI_BROTHERHOOD_INITIATE);
		initialized1 := 1;
	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
			else begin
				if (script_action == talk_proc) then begin
					call talk_p_proc;
				end
			end
		end
	end
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
end

procedure destroy_p_proc
begin
	set_global_var(GVAR_ENEMY_BROTHERHOOD, 1);
	rm_timer_event(self_obj);
	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 talk_p_proc
begin
	start_gdialog(SCRIPT_BRENDEN, self_obj, 4, -1, -1);
	gsay_start;
	call Brenden01;
	gsay_end;
	end_dialogue;
end

procedure Brenden01
begin
	if (local_var(0)) then begin
		gsay_reply(SCRIPT_BRENDEN, 112);
	end
	else begin
		set_local_var(0, 1);
		gsay_reply(SCRIPT_BRENDEN, 102);
	end
	giq_option(-3, SCRIPT_BRENDEN, 107, Brenden05, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_BRENDEN, 103, Brenden02, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_BRENDEN, 104, Brenden03, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_BRENDEN, 105, Brenden04, NEUTRAL_REACTION);
	if (local_var(1) == 0) then begin
		giq_option(4, SCRIPT_BRENDEN, 106, Brenden06, NEUTRAL_REACTION);
	end
	giq_option(4, SCRIPT_BRENDEN, 113, BrendenEnd, NEUTRAL_REACTION);
end

procedure Brenden02
begin
	gsay_reply(SCRIPT_BRENDEN, 109);
	giq_option(0, SCRIPT_MODREACT, 106, Brenden01, NEUTRAL_REACTION);
end

procedure Brenden03
begin
	gsay_reply(SCRIPT_BRENDEN, 110);
	giq_option(0, SCRIPT_MODREACT, 106, Brenden01, NEUTRAL_REACTION);
end

procedure Brenden04
begin
	gsay_reply(SCRIPT_BRENDEN, 111);
	giq_option(0, SCRIPT_MODREACT, 106, Brenden01, NEUTRAL_REACTION);
end

procedure Brenden05
begin
	gsay_message(SCRIPT_BRENDEN, 108, NEUTRAL_REACTION);
end

procedure Brenden06
begin
	set_local_var(1, 1);
	gsay_reply(SCRIPT_BRENDEN, 114);
	giq_option(4, SCRIPT_BRENDEN, 115, Brenden07, GOOD_REACTION);
	giq_option(4, SCRIPT_BRENDEN, 116, Brenden12, BAD_REACTION);
	giq_option(4, SCRIPT_BRENDEN, 113, BrendenEnd, NEUTRAL_REACTION);
end

procedure Brenden07
begin
	gsay_reply(SCRIPT_BRENDEN, 117);
	giq_option(6, SCRIPT_BRENDEN, 118, Brenden08, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_BRENDEN, 119, Brenden11, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_BRENDEN, 113, BrendenEnd, NEUTRAL_REACTION);
end

procedure Brenden08
begin
	gsay_reply(SCRIPT_BRENDEN, 120);
	giq_option(6, SCRIPT_BRENDEN, 121, Brenden09, GOOD_REACTION);
	giq_option(4, SCRIPT_BRENDEN, 113, BrendenEnd, NEUTRAL_REACTION);
end

procedure Brenden09
begin
	gsay_reply(SCRIPT_BRENDEN, 122);
	giq_option(6, SCRIPT_BRENDEN, 123, Brenden10, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_BRENDEN, 113, BrendenEnd, NEUTRAL_REACTION);
end

procedure Brenden10
begin
	gsay_reply(SCRIPT_BRENDEN, 124);
	giq_option(4, SCRIPT_BRENDEN, 113, BrendenEnd, NEUTRAL_REACTION);
end

procedure Brenden11
begin
	gsay_reply(SCRIPT_BRENDEN, 125);
	giq_option(4, SCRIPT_BRENDEN, 126, Brenden09, GOOD_REACTION);
	giq_option(4, SCRIPT_BRENDEN, 113, BrendenEnd, NEUTRAL_REACTION);
end

procedure Brenden12
begin
	gsay_message(SCRIPT_BRENDEN, 127, BAD_REACTION);
end

procedure BrendenEnd
begin
end