#include <define.h>

//#define NAME                    SCRIPT_

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



procedure start;
#include <push.h>
procedure do_dialogue;
procedure end_employment;
procedure hiring;
procedure follow_player;
procedure vasquez01;
procedure vasquez00;
procedure vasquezend;
procedure vasquez10;
procedure vasquez02;
procedure vasquez03;
procedure vasquez04;
procedure vasquez05;
procedure vasquez06;
procedure vasquez07;
procedure vasquez08;
procedure vasquez09;

variable known;
variable warned;
variable following;
variable hire_date;


procedure start
begin
	if (script_action == talk_proc) then begin
		call do_dialogue;
	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_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
		else begin
			if ((script_action == look_at_proc) or (script_action == description_proc)) then begin
				script_overrides;
				if (known) then begin
					display_msg(message_str(SCRIPT_VASQUEZ, 100));
				end
				else begin
					display_msg(message_str(SCRIPT_VASQUEZ, 101));
				end
			end
			else begin
				if (script_action == critter_proc) then begin
					if (following) then begin
						if (((game_time / (10 * 60 * 60 * 24)) - hire_date) > 7) then begin
							call end_employment;
						end
						else begin
							call follow_player;
						end
					end
					else begin
						if (script_action == damage_proc) then begin
							if (source_obj == dude_obj) then begin
								if (not(warned)) then begin
									call vasquez10;
								end
							end
						end
					end
				end
			end
		end
	end
end

procedure do_dialogue
begin
	start_gdialog(SCRIPT_VASQUEZ, self_obj, 4, -1, -1);
	gsay_start;
	if (following) then begin
		call vasquez06;
	end
	else begin
		if (known) then begin
			call vasquez07;
		end
		else begin
			call vasquez00;
		end
	end
	gsay_end;
	end_dialogue;
end

procedure end_employment
begin
	following := 0;
end

procedure hiring
begin
	call vasquez05;
end

procedure follow_player
begin
	if (tile_distance_objs(self_obj, dude_obj) > 3) then begin
		animate_move_obj_to_tile(self_obj, tile_num(dude_obj), ANIMATE_WALK);
	end
	else begin
		if (anim_busy(self_obj)) then begin
			animate_move_obj_to_tile(self_obj, tile_num(self_obj), ANIMATE_WALK);
		end
	end
end

procedure vasquez01
begin
	gsay_message(SCRIPT_VASQUEZ, 105, NEUTRAL_REACTION);
end

procedure vasquez00
begin
	gsay_reply(SCRIPT_VASQUEZ, 102);
	giq_option(4, SCRIPT_VASQUEZ, 103, vasquez02, NEUTRAL_REACTION);
	giq_option(-3, SCRIPT_VASQUEZ, 104, vasquez01, NEUTRAL_REACTION);
end

procedure vasquezend
begin
end

procedure vasquez10
begin
	float_msg(self_obj, message_str(SCRIPT_VASQUEZ, 126), FLOAT_MSG_NORMAL);
	warned := 1;
end

procedure vasquez02
begin
	known := 1;
	gsay_reply(SCRIPT_VASQUEZ, 106);
	giq_option(4, SCRIPT_VASQUEZ, 107, vasquez03, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_VASQUEZ, 108, vasquezend, NEUTRAL_REACTION);
end

procedure vasquez03
begin
	gsay_reply(SCRIPT_VASQUEZ, 109);
	giq_option(4, SCRIPT_VASQUEZ, 110, hiring, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_VASQUEZ, 111, vasquezend, NEUTRAL_REACTION);
end

procedure vasquez04
begin
	gsay_message(SCRIPT_VASQUEZ, 112, NEUTRAL_REACTION);
end

procedure vasquez05
begin
	gsay_message(SCRIPT_VASQUEZ, 113, NEUTRAL_REACTION);
	following := 1;
	hire_date := game_time / (10 * 60 * 60 * 24);
end

procedure vasquez06
begin
	variable LVar0 := 0;
	variable LVar1 := 0;
	LVar0 := random(1, 5);
	if (LVar0 == 1) then begin
		LVar1 := message_str(SCRIPT_VASQUEZ, 114);
	end
	else begin
		if (LVar0 == 2) then begin
			LVar1 := message_str(SCRIPT_VASQUEZ, 115);
		end
		else begin
			if (LVar0 == 3) then begin
				LVar1 := message_str(SCRIPT_VASQUEZ, 116);
			end
			else begin
				if (LVar0 == 4) then begin
					LVar1 := message_str(SCRIPT_VASQUEZ, 117);
				end
				else begin
					if (LVar0 == 5) then begin
						LVar1 := message_str(SCRIPT_VASQUEZ, 118);
					end
				end
			end
		end
	end
	float_msg(self_obj, LVar1, FLOAT_MSG_NORMAL);
end

procedure vasquez07
begin
	gsay_reply(SCRIPT_VASQUEZ, 119);
	giq_option(4, SCRIPT_VASQUEZ, 120, vasquez09, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_VASQUEZ, 121, vasquezend, NEUTRAL_REACTION);
	giq_option(-3, SCRIPT_VASQUEZ, 122, vasquez08, NEUTRAL_REACTION);
end

procedure vasquez08
begin
	gsay_message(SCRIPT_VASQUEZ, 123, NEUTRAL_REACTION);
end

procedure vasquez09
begin
	gsay_reply(SCRIPT_VASQUEZ, 124);
	giq_option(4, SCRIPT_VASQUEZ, 125, hiring, NEUTRAL_REACTION);
end