#include <define.h>

//#define NAME                    SCRIPT_

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



procedure start;
#include <push.h>
procedure do_dialogue;
procedure ghoulend;
procedure ghoulcbt;
procedure ghoul00;
procedure ghoul01;
procedure ghoul02;
procedure ghoul03;
procedure ghoul04;
procedure ghoul04a;
procedure ghoul05;
procedure ghoul06;
procedure ghoul07;
procedure ghoul08;
procedure ghoul09;
procedure ghoul10;
procedure ghoul11;
procedure ghoul12;
procedure ghoul13;

variable Hostile;
variable init_teams;


procedure start
begin
	if (not(init_teams)) then begin
		critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_TEAM_NUM, 30);
		critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_AI_PACKET, AI_GHOUL_BRAVE);
		init_teams := 1;
	end
	if (script_action == talk_proc) then begin
		call do_dialogue;
	end
	else begin
		if (script_action == look_at_proc) then begin
			script_overrides;
			display_msg(message_str(SCRIPT_GANGER, 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
				end
			end
		end
	end
end

procedure do_dialogue
begin
	start_gdialog(SCRIPT_GANGER, self_obj, 4, -1, -1);
	gsay_start;
	if (local_var(0)) then begin
		call ghoul08;
	end
	else begin
		set_local_var(0, 1);
		call ghoul00;
	end
	gsay_end;
	end_dialogue;
end

procedure ghoulend
begin
end

procedure ghoulcbt
begin
	Hostile := 1;
end

procedure ghoul00
begin
	gsay_reply(SCRIPT_GANGER, 101);
	giq_option(6, SCRIPT_GANGER, 102, ghoul01, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_GANGER, 103, ghoul08, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_GANGER, 104, ghoul11, NEUTRAL_REACTION);
	giq_option(-3, SCRIPT_GANGER, 105, ghoul12, NEUTRAL_REACTION);
end

procedure ghoul01
begin
	gsay_reply(SCRIPT_GANGER, 106);
	giq_option(6, SCRIPT_GANGER, 107, ghoulend, NEUTRAL_REACTION);
	giq_option(6, SCRIPT_GANGER, 108, ghoul02, NEUTRAL_REACTION);
	giq_option(6, SCRIPT_GANGER, 109, ghoulcbt, BAD_REACTION);
end

procedure ghoul02
begin
	gsay_reply(SCRIPT_GANGER, 110);
	giq_option(5, SCRIPT_GANGER, 111, ghoul04, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_GANGER, 112, ghoul05, NEUTRAL_REACTION);
end

procedure ghoul03
begin
	gsay_reply(SCRIPT_GANGER, 113);
	giq_option(8, SCRIPT_GANGER, 114, ghoul05, NEUTRAL_REACTION);
end

procedure ghoul04
begin
	if (is_success(roll_vs_skill(dude_obj, 14, 0))) then begin
		call ghoul03;
	end
	else begin
		call ghoul04a;
	end
end

procedure ghoul04a
begin
	gsay_message(SCRIPT_GANGER, 115, NEUTRAL_REACTION);
	call ghoulend;
end

procedure ghoul05
begin
	gsay_reply(SCRIPT_GANGER, 116);
	giq_option(5, SCRIPT_GANGER, 117, ghoul06, NEUTRAL_REACTION);
	giq_option(5, SCRIPT_GANGER, 118, ghoulend, NEUTRAL_REACTION);
end

procedure ghoul06
begin
	gsay_reply(SCRIPT_GANGER, 119);
	giq_option(5, SCRIPT_GANGER, 120, ghoul07, NEUTRAL_REACTION);
	giq_option(5, SCRIPT_GANGER, 121, ghoulend, NEUTRAL_REACTION);
end

procedure ghoul07
begin
	gsay_message(SCRIPT_GANGER, 122, NEUTRAL_REACTION);
	call ghoulend;
end

procedure ghoul08
begin
	gsay_reply(SCRIPT_GANGER, 123);
	giq_option(4, SCRIPT_GANGER, 124, ghoul09, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_GANGER, 125, ghoulend, NEUTRAL_REACTION);
	giq_option(-3, SCRIPT_GANGER, 105, ghoul12, NEUTRAL_REACTION);
end

procedure ghoul09
begin
	gsay_reply(SCRIPT_GANGER, 126);
	giq_option(4, SCRIPT_GANGER, 127, ghoul10, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_GANGER, 128, ghoulend, NEUTRAL_REACTION);
end

procedure ghoul10
begin
	gsay_reply(SCRIPT_GANGER, 129);
	call ghoulcbt;
end

procedure ghoul11
begin
	gsay_message(SCRIPT_GANGER, 130, NEUTRAL_REACTION);
	call ghoulend;
end

procedure ghoul12
begin
	gsay_message(SCRIPT_GANGER, 131, NEUTRAL_REACTION);
	call ghoulcbt;
end

procedure ghoul13
begin
	gsay_message(SCRIPT_GANGER, 132, NEUTRAL_REACTION);
	call ghoulend;
end