#include <define.h>

//#define NAME                    SCRIPT_

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



procedure start;
#include <push.h>
procedure destroy_p_proc;
procedure talk_p_proc;
procedure critter_p_proc;
procedure Dealer00;
procedure Dealer01;
procedure Dealer02;
procedure Dealer03;
procedure Dealer04;
procedure Dealer05;
procedure Dealer06;
procedure Dealer07;
procedure Dealer08;
procedure DealerEnd;

variable initialized1;
variable said_hi;


procedure start
begin
	variable LVar0 := 0;
	if (not(initialized1)) then begin
		if (metarule(14, 0)) then begin
			LVar0 := create_object_sid(41, 0, 0, -1);
			add_mult_objs_to_inven(self_obj, LVar0, random(0, 100));
			critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_TEAM_NUM, 24);
			set_global_var(GVAR_WATER_THIEF_2, 0);
		end
		initialized1 := 1;
	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
			else begin
				if (script_action == critter_proc) then begin
					call critter_p_proc;
				end
			end
		end
	end
end

procedure destroy_p_proc
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_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
	if (global_var(GVAR_WATER_THIEF_2) == 1) then begin
		float_msg(self_obj, message_str(SCRIPT_DEALER, random(127, 130)), FLOAT_MSG_NORMAL);
	end
	else begin
		start_gdialog(SCRIPT_DEALER, self_obj, 4, -1, -1);
		gsay_start;
		call Dealer00;
		gsay_end;
		end_dialogue;
	end
end

procedure critter_p_proc
begin
	if (not(said_hi) and (tile_distance_objs(self_obj, dude_obj) <= 6)) then begin
		float_msg(self_obj, message_str(SCRIPT_DEALER, 131), FLOAT_MSG_NORMAL);
		said_hi := 1;
	end
end

procedure Dealer00
begin
	set_global_var(GVAR_WATER_THIEF_2, 1);
	gsay_reply(SCRIPT_DEALER, 100);
	giq_option(4, SCRIPT_DEALER, 101, Dealer02, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DEALER, 102, DealerEnd, NEUTRAL_REACTION);
	giq_option(-3, SCRIPT_DEALER, 103, Dealer01, NEUTRAL_REACTION);
end

procedure Dealer01
begin
	gsay_message(SCRIPT_DEALER, 104, NEUTRAL_REACTION);
end

procedure Dealer02
begin
	if (dude_is_male) then begin
		gsay_reply(SCRIPT_DEALER, 105);
	end
	else begin
		gsay_reply(SCRIPT_DEALER, 106);
	end
	giq_option(4, SCRIPT_DEALER, 107, Dealer03, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DEALER, 108, DealerEnd, NEUTRAL_REACTION);
end

procedure Dealer03
begin
	gsay_reply(SCRIPT_DEALER, 109);
	giq_option(4, SCRIPT_DEALER, 110, Dealer04, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DEALER, 111, Dealer08, BAD_REACTION);
	giq_option(4, SCRIPT_DEALER, 112, DealerEnd, NEUTRAL_REACTION);
end

procedure Dealer04
begin
	if (dude_is_male) then begin
		gsay_reply(SCRIPT_DEALER, 113);
	end
	else begin
		gsay_reply(SCRIPT_DEALER, 114);
	end
	giq_option(4, SCRIPT_DEALER, 115, Dealer05, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DEALER, 116, Dealer08, BAD_REACTION);
	giq_option(4, SCRIPT_DEALER, 112, DealerEnd, NEUTRAL_REACTION);
end

procedure Dealer05
begin
	gsay_reply(SCRIPT_DEALER, 117);
	giq_option(4, SCRIPT_DEALER, 118, Dealer06, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DEALER, 119, Dealer08, BAD_REACTION);
	giq_option(4, SCRIPT_DEALER, 120, DealerEnd, NEUTRAL_REACTION);
end

procedure Dealer06
begin
	gsay_reply(SCRIPT_DEALER, 121);
	giq_option(4, SCRIPT_DEALER, 122, Dealer07, GOOD_REACTION);
	giq_option(4, SCRIPT_DEALER, 123, Dealer08, BAD_REACTION);
	giq_option(4, SCRIPT_DEALER, 124, DealerEnd, NEUTRAL_REACTION);
end

procedure Dealer07
begin
	gsay_message(SCRIPT_DEALER, 125, GOOD_REACTION);
end

procedure Dealer08
begin
	gsay_message(SCRIPT_DEALER, 126, BAD_REACTION);
end

procedure DealerEnd
begin
end