#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 look_at_p_proc;
procedure pickup_p_proc;
procedure talk_p_proc;
procedure Hunter01;
procedure Hunter02;
procedure Hunter03;
procedure Hunter04;
procedure Hunter05;

variable mad;
variable hostile1;
variable initialized1;
variable my_script_mode;
variable pre_fight;

import variable removal_ptr;


procedure start
begin
	if (not(initialized1)) then begin
		critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_TEAM_NUM, 29);
		if (cur_map_index != MAP_LAFOLLWR) then begin
			call Hunter05;
			attack_complex(dude_obj, 0, 1, 0, 0, 30000, 0, 0);
			my_script_mode := 1;
		end
		else begin
			if (global_var(GVAR_HUNTER_STATUS) == 3) then begin
				move_to(self_obj, 7000, 0);
				removal_ptr := self_obj;
			end
		end
		initialized1 := 1;
	end
	else begin
		if (not(my_script_mode)) then 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 == look_at_proc) then begin
						call look_at_p_proc;
					end
					else begin
						if (script_action == pickup_proc) then begin
							call pickup_p_proc;
						end
						else begin
							if (script_action == talk_proc) then begin
								call talk_p_proc;
							end
						end
					end
				end
			end
		end
		else begin
			if (script_action == destroy_proc) then begin
				call destroy_p_proc;
			end
		end
	end
end

procedure critter_p_proc
begin
	if (hostile1) then begin
		hostile1 := 0;
		attack_complex(dude_obj, 0, 1, 0, 0, 30000, 0, 0);
	end
	else begin
		if (obj_can_see_obj(self_obj, dude_obj) and not(my_script_mode) and not(pre_fight) and (global_var(GVAR_CHILDKILLER_REPUTATION) > 2)) then begin
			call Hunter05;
			pre_fight := 1;
		end
	end
end

procedure destroy_p_proc
begin
	set_global_var(GVAR_HUNTER_STATUS, 3);
	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 look_at_p_proc
begin
	script_overrides;
	display_msg(message_str(SCRIPT_HUNTER, 100));
end

procedure pickup_p_proc
begin
	hostile1 := 1;
end

procedure talk_p_proc
begin
	start_gdialog(SCRIPT_HUNTER, self_obj, 4, -1, -1);
	gsay_start;
	call Hunter01;
	gsay_end;
	end_dialogue;
end

procedure Hunter01
begin
	gsay_reply(SCRIPT_HUNTER, 101);
	giq_option(3, SCRIPT_HUNTER, 102, Hunter02, NEUTRAL_REACTION);
	giq_option(3, SCRIPT_HUNTER, 103, Hunter03, NEUTRAL_REACTION);
	giq_option(3, SCRIPT_HUNTER, 104, Hunter04, NEUTRAL_REACTION);
	giq_option(0, SCRIPT_HUNTER, 105, Hunter04, NEUTRAL_REACTION);
end

procedure Hunter02
begin
	if (not(mad)) then begin
		gsay_message(SCRIPT_HUNTER, 106, NEUTRAL_REACTION);
		mad := 1;
	end
	else begin
		gsay_message(SCRIPT_HUNTER, 107, NEUTRAL_REACTION);
		hostile1 := 1;
	end
end

procedure Hunter03
begin
	gsay_message(SCRIPT_HUNTER, 108, NEUTRAL_REACTION);
end

procedure Hunter04
begin
	gsay_message(SCRIPT_HUNTER, 109, NEUTRAL_REACTION);
end

procedure Hunter05
begin
	float_msg(self_obj, message_str(SCRIPT_HUNTER, 110), FLOAT_MSG_NORMAL);
	hostile1 := 1;
end