#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 talk_p_proc;
procedure Marney00;
procedure Marney01;
procedure Marney02;
procedure Marney03;
procedure Marney04;
procedure Marney05;
procedure Marney06;
procedure Marney07;
procedure MarneyEnd;

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_LEADER);
		initialized1 := 1;
	end
	else 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 == talk_proc) then begin
						call talk_p_proc;
					end
				end
			end
		end
	end
end

procedure critter_p_proc
begin
	if (global_var(GVAR_DESTROY_FOLLOWERS) == 2) then begin
		kill_critter(self_obj, 59);
	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
	script_overrides;
	if (local_var(0)) then begin
		if ((game_time_hour >= 1900) or (game_time_hour < 600)) then begin
			display_msg(message_str(SCRIPT_MARNEY, 100));
		end
		else begin
			display_msg(message_str(SCRIPT_MARNEY, 101));
		end
	end
	else begin
		if ((game_time_hour >= 1900) or (game_time_hour < 600)) then begin
			display_msg(message_str(SCRIPT_MARNEY, 102));
		end
		else begin
			display_msg(message_str(SCRIPT_MARNEY, 103));
		end
	end
end

procedure talk_p_proc
begin
	start_gdialog(SCRIPT_MARNEY, self_obj, 4, -1, -1);
	gsay_start;
	set_local_var(0, 1);
	call Marney00;
	gsay_end;
	end_dialogue;
end

procedure Marney00
begin
	variable LVar0 := 0;
	LVar0 := get_critter_stat(dude_obj, 7) - get_critter_stat(dude_obj, 35);
	gsay_reply(SCRIPT_MARNEY, 104);
	giq_option(-3, SCRIPT_MARNEY, 105, Marney01, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_MARNEY, 125, MarneyEnd, NEUTRAL_REACTION);
	if (LVar0 > 0) then begin
		giq_option(4, SCRIPT_MARNEY, 106, Marney01, NEUTRAL_REACTION);
	end
	if (not(local_var(2))) then begin
		giq_option(5, SCRIPT_MARNEY, 107, Marney06, NEUTRAL_REACTION);
	end
end

procedure Marney01
begin
	gsay_reply(SCRIPT_MARNEY, 108);
	giq_option(-3, SCRIPT_MARNEY, 109, Marney02, NEUTRAL_REACTION);
	giq_option(-3, SCRIPT_MARNEY, 110, Marney05, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_MARNEY, 111, Marney02, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_MARNEY, 112, Marney05, NEUTRAL_REACTION);
end

procedure Marney02
begin
	variable LVar0 := 0;
	gfade_out(600);
	gfade_in(600);
	LVar0 := get_critter_stat(dude_obj, 7) - get_critter_stat(dude_obj, 35);
	game_time_advance(game_ticks(60 * 20 * LVar0));
	critter_heal(dude_obj, LVar0);
	gsay_message(SCRIPT_MARNEY, 113, NEUTRAL_REACTION);
	if (not(local_var(1))) then begin
		giq_option(4, SCRIPT_MARNEY, 114, Marney03, NEUTRAL_REACTION);
	end
	giq_option(4, SCRIPT_MARNEY, 115, MarneyEnd, NEUTRAL_REACTION);
end

procedure Marney03
begin
	gsay_reply(SCRIPT_MARNEY, 116);
	giq_option(4, SCRIPT_MARNEY, 117, Marney04, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_MARNEY, 118, Marney05, NEUTRAL_REACTION);
end

procedure Marney04
begin
	gfade_out(600);
	gfade_in(600);
	game_time_advance(game_ticks(18000));
	critter_mod_skill(dude_obj, 6, 15);
	set_local_var(1, 1);
	gsay_message(SCRIPT_MARNEY, 119, NEUTRAL_REACTION);
end

procedure Marney05
begin
	gsay_message(SCRIPT_MARNEY, 120, NEUTRAL_REACTION);
end

procedure Marney06
begin
	gsay_reply(SCRIPT_MARNEY, 121);
	giq_option(5, SCRIPT_MARNEY, 122, Marney07, NEUTRAL_REACTION);
	giq_option(5, SCRIPT_MARNEY, 123, Marney05, NEUTRAL_REACTION);
end

procedure Marney07
begin
	gfade_out(600);
	gfade_in(600);
	game_time_advance(game_ticks(25200));
	critter_mod_skill(dude_obj, 7, 15);
	set_local_var(2, 1);
	gsay_message(SCRIPT_MARNEY, 124, NEUTRAL_REACTION);
end

procedure MarneyEnd
begin
end