#include <define.h>

//#define NAME                    SCRIPT_

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



procedure start;
#include <push.h>
procedure Brat02;
procedure Brat03;
procedure Brat04;
procedure Brat05;
procedure Brat06;
procedure Brat07;
procedure Combat;
procedure BratEnd;

variable Hostile;
variable Only_Once := 1;


procedure start
begin
	if (Only_Once) then begin
		critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_TEAM_NUM, 20);
		critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_AI_PACKET, AI_CHILDREN_TRUE);
		Only_Once := 0;
	end
	if ((script_action == look_at_proc) or (script_action == description_proc)) then begin
		script_overrides;
		display_msg(message_str(SCRIPT_CHIDGAB, 100));
	end
	else begin
		if (script_action == pickup_proc) then begin
			Hostile := 1;
		end
		else begin
			if (script_action == critter_proc) then begin
				if (Hostile) then begin
					Hostile := 0;
					attack_complex(dude_obj, 0, 1, 0, 0, 30000, 0, 0);
				end
			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_BAD_MONSTER, global_var(GVAR_BAD_MONSTER) + 1);
						if ((global_var(GVAR_BAD_MONSTER) % 6) == 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 (global_var(GVAR_CATHEDRAL_ENEMY) == 1) 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)) or (global_var(GVAR_CHILDKILLER_REPUTATION) > 2)) then begin
								float_msg(self_obj, message_str(SCRIPT_CHIDGAB, 102), FLOAT_MSG_NORMAL);
							end
							else begin
								float_msg(self_obj, message_str(SCRIPT_CHIDGAB, 101), FLOAT_MSG_NORMAL);
							end
						end
						else begin
							start_gdialog(SCRIPT_CHIDGAB, self_obj, 4, -1, -1);
							gsay_start;
							call Brat02;
							gsay_end;
							end_dialogue;
						end
					end
				end
			end
		end
	end
end

procedure Brat02
begin
	gsay_reply(SCRIPT_CHIDGAB, 103);
	giq_option(7, SCRIPT_CHIDGAB, 104, Brat03, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_CHIDGAB, 105, Brat04, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_CHIDGAB, 106, Brat05, NEUTRAL_REACTION);
	if (global_var(GVAR_ALOCHOL_ADDICT) == 1) then begin
		giq_option(4, SCRIPT_CHIDGAB, 107, Brat06, NEUTRAL_REACTION);
	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
		giq_option(4, SCRIPT_CHIDGAB, 108, Brat07, NEUTRAL_REACTION);
	end
	giq_option(-3, SCRIPT_CHIDGAB, 109, Brat07, NEUTRAL_REACTION);
end

procedure Brat03
begin
	gsay_reply(SCRIPT_CHIDGAB, 110);
	gsay_option(SCRIPT_CHIDGAB, 115, BratEnd, NEUTRAL_REACTION);
end

procedure Brat04
begin
	gsay_reply(SCRIPT_CHIDGAB, 111);
	gsay_option(SCRIPT_CHIDGAB, 115, BratEnd, NEUTRAL_REACTION);
end

procedure Brat05
begin
	gsay_reply(SCRIPT_CHIDGAB, 112);
	gsay_option(SCRIPT_CHIDGAB, 115, BratEnd, NEUTRAL_REACTION);
end

procedure Brat06
begin
	gsay_reply(SCRIPT_CHIDGAB, 113);
	gsay_option(SCRIPT_CHIDGAB, 115, BratEnd, NEUTRAL_REACTION);
end

procedure Brat07
begin
	gsay_reply(SCRIPT_CHIDGAB, 114);
	gsay_option(SCRIPT_CHIDGAB, 115, BratEnd, NEUTRAL_REACTION);
end

procedure Combat
begin
	Hostile := 1;
end

procedure BratEnd
begin
end