#include <define.h>

//#define NAME                    SCRIPT_

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



procedure start;
#include <push.h>
procedure destroy_p_proc;
procedure look_at_p_proc;
procedure talk_p_proc;
procedure peter0;
procedure peter1;
procedure peter2;
procedure peter3;
procedure peter4;
procedure peter4a;
procedure peter5;
procedure peter6;
procedure peter7;
procedure peter8;
procedure peter9;
procedure peter10;
procedure peterend;

variable initialized1;


procedure start
begin
	if (not(initialized1)) then begin
		critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_TEAM_NUM, 46);
		critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_AI_PACKET, AI_FOLLOWER_GUARD);
		initialized1 := 1;
		if (global_var(GVAR_DESTROY_FOLLOWERS) == 2) then begin
			if (random(0, 1)) then begin
				kill_critter(self_obj, 59);
			end
			else begin
				kill_critter(self_obj, 57);
			end
		end
	end
	else begin
		if (script_action == destroy_proc) then begin
			call destroy_p_proc;
		end
	end
	if (script_action == look_at_proc) then begin
		call look_at_p_proc;
	end
	else begin
		if (script_action == talk_proc) then begin
			call talk_p_proc;
		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 look_at_p_proc
begin
	if (local_var(0)) then begin
		script_overrides;
		display_msg(message_str(SCRIPT_PETER, 100));
	end
end

procedure talk_p_proc
begin
	set_local_var(0, 1);
	script_overrides;
	if (global_var(GVAR_FIND_AGENT) == 1) then begin
		call peter9;
	end
	else begin
		if (global_var(GVAR_FIND_AGENT) == 2) then begin
			call peter10;
		end
		else begin
			if ((game_time_hour >= 700) and (game_time_hour < 1800)) then begin
				start_gdialog(SCRIPT_PETER, self_obj, 4, -1, -1);
				gsay_start;
				call peter0;
				gsay_end;
				end_dialogue;
			end
			else begin
				call peter8;
			end
		end
	end
end

procedure peter0
begin
	gsay_reply(SCRIPT_PETER, 101);
	giq_option(-3, SCRIPT_PETER, 102, peter1, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_PETER, 103, peterend, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_PETER, 104, peter2, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_PETER, 105, peter7, NEUTRAL_REACTION);
end

procedure peter1
begin
	gsay_message(SCRIPT_PETER, 106, NEUTRAL_REACTION);
end

procedure peter2
begin
	gsay_reply(SCRIPT_PETER, 107);
	giq_option(4, SCRIPT_PETER, 108, peter3, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_PETER, 109, peter4, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_PETER, 110, peter6, NEUTRAL_REACTION);
end

procedure peter3
begin
	gsay_message(SCRIPT_PETER, 111, NEUTRAL_REACTION);
end

procedure peter4
begin
	gsay_reply(SCRIPT_PETER, 112);
	giq_option(4, SCRIPT_PETER, 113, peter4a, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_PETER, 114, peter5, NEUTRAL_REACTION);
end

procedure peter4a
begin
	set_global_var(GVAR_FIND_AGENT, 1);
end

procedure peter5
begin
	gsay_message(SCRIPT_PETER, 115, NEUTRAL_REACTION);
end

procedure peter6
begin
	gsay_reply(SCRIPT_PETER, 116);
	giq_option(4, SCRIPT_PETER, 117, peter4a, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_PETER, 118, peter5, NEUTRAL_REACTION);
end

procedure peter7
begin
	gsay_message(SCRIPT_PETER, 119, NEUTRAL_REACTION);
end

procedure peter8
begin
	float_msg(self_obj, message_str(SCRIPT_PETER, 120), FLOAT_MSG_NORMAL);
end

procedure peter9
begin
	float_msg(self_obj, message_str(SCRIPT_PETER, 121), FLOAT_MSG_NORMAL);
end

procedure peter10
begin
	variable LVar0 := 0;
	float_msg(self_obj, message_str(SCRIPT_PETER, 122), FLOAT_MSG_NORMAL);
	if (local_var(1) == 0) then begin
		set_local_var(1, 1);
		LVar0 := create_object_sid(40, 0, 0, -1);
		add_obj_to_inven(dude_obj, LVar0);
		LVar0 := create_object_sid(40, 0, 0, -1);
		add_obj_to_inven(dude_obj, LVar0);
		LVar0 := create_object_sid(40, 0, 0, -1);
		add_obj_to_inven(dude_obj, LVar0);
	end
end

procedure peterend
begin
end