#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 Jason01;
procedure Jason02;
procedure Jason03;
procedure Jason04;
procedure Jason05;
procedure Jason06;
procedure Jason07;
procedure Jason08;
procedure Jason09;
procedure Jason10;
procedure Jason11;
procedure Jason12;
procedure Jason13;
procedure Jason14;
procedure Jason15;
procedure Jason16;
procedure Jason17;
procedure Jason18;
procedure Jason19;
procedure Jason20;
procedure Jason21;
procedure Jason22;
procedure Jason23;
procedure follow_player;

variable following;
variable initialized1;


procedure start
begin
	if (not(initialized1)) then begin
		critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_TEAM_NUM, 49);
		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 (following) then begin
		call follow_player;
	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 (not(local_var(1))) then begin
		display_msg(message_str(SCRIPT_JASON, 101));
	end
	else begin
		display_msg(message_str(SCRIPT_JASON, 100));
	end
end

procedure talk_p_proc
begin
	start_gdialog(SCRIPT_JASON, self_obj, 4, -1, -1);
	gsay_start;
	if (cur_map_index == MAP_LARIPPER) then begin
		if (following) then begin
			call Jason23;
		end
		else begin
			call Jason19;
		end
	end
	if (local_var(0)) then begin
		call Jason18;
	end
	else begin
		if (local_var(1)) then begin
			call Jason16;
		end
		else begin
			call Jason01;
		end
	end
	gsay_end;
	end_dialogue;
end

procedure Jason01
begin
	gsay_reply(SCRIPT_JASON, 102);
	giq_option(4, SCRIPT_JASON, 103, Jason05, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_JASON, 104, Jason13, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_JASON, 105, Jason08, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_JASON, 106, Jason07, NEUTRAL_REACTION);
	giq_option(-3, SCRIPT_JASON, 107, Jason02, NEUTRAL_REACTION);
end

procedure Jason02
begin
	gsay_message(SCRIPT_JASON, 108, NEUTRAL_REACTION);
end

procedure Jason03
begin
	gsay_message(SCRIPT_JASON, 109, NEUTRAL_REACTION);
	gsay_message(SCRIPT_JASON, 110, NEUTRAL_REACTION);
end

procedure Jason04
begin
	gsay_message(SCRIPT_JASON, 111, NEUTRAL_REACTION);
	gsay_message(SCRIPT_JASON, 112, NEUTRAL_REACTION);
end

procedure Jason05
begin
	gsay_reply(SCRIPT_JASON, 113);
	giq_option(4, SCRIPT_JASON, 114, Jason06, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_JASON, 115, Jason14, NEUTRAL_REACTION);
end

procedure Jason06
begin
	gsay_reply(SCRIPT_JASON, 116);
	giq_option(4, SCRIPT_JASON, 117, Jason07, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_JASON, 118, Jason08, NEUTRAL_REACTION);
	giq_option(6, SCRIPT_JASON, 119, Jason15, NEUTRAL_REACTION);
end

procedure Jason07
begin
	gsay_reply(SCRIPT_JASON, 120);
	giq_option(4, SCRIPT_JASON, 121, Jason12, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_JASON, 122, Jason08, NEUTRAL_REACTION);
end

procedure Jason08
begin
	gsay_reply(SCRIPT_JASON, 123);
	giq_option(4, SCRIPT_JASON, 124, Jason12, NEUTRAL_REACTION);
end

procedure Jason09
begin
	gsay_reply(SCRIPT_JASON, 125);
	giq_option(4, SCRIPT_JASON, 126, Jason10, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_JASON, 127, Jason11, NEUTRAL_REACTION);
end

procedure Jason10
begin
	gsay_message(SCRIPT_JASON, 128, NEUTRAL_REACTION);
end

procedure Jason11
begin
	gsay_message(SCRIPT_JASON, 129, NEUTRAL_REACTION);
end

procedure Jason12
begin
	gsay_message(SCRIPT_JASON, 130, NEUTRAL_REACTION);
end

procedure Jason13
begin
	gsay_message(SCRIPT_JASON, 131, NEUTRAL_REACTION);
	set_local_var(0, 1);
end

procedure Jason14
begin
	gsay_message(SCRIPT_JASON, 132, NEUTRAL_REACTION);
	call Jason10;
end

procedure Jason15
begin
	gsay_message(SCRIPT_JASON, 133, NEUTRAL_REACTION);
	call Jason11;
end

procedure Jason16
begin
	gsay_reply(SCRIPT_JASON, 134);
	giq_option(4, SCRIPT_JASON, 135, Jason08, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_JASON, 136, Jason17, NEUTRAL_REACTION);
end

procedure Jason17
begin
	gsay_message(SCRIPT_JASON, 137, NEUTRAL_REACTION);
end

procedure Jason18
begin
	gsay_message(SCRIPT_JASON, 138, NEUTRAL_REACTION);
end

procedure Jason19
begin
	gsay_reply(SCRIPT_JASON, 139);
	giq_option(-3, SCRIPT_JASON, 140, Jason20, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_JASON, 141, Jason20, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_JASON, 142, Jason21, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_JASON, 143, Jason22, NEUTRAL_REACTION);
end

procedure Jason20
begin
	gsay_message(SCRIPT_JASON, 144, NEUTRAL_REACTION);
	critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_TEAM_NUM, 0);
	following := 1;
end

procedure Jason21
begin
	gsay_message(SCRIPT_JASON, 145, NEUTRAL_REACTION);
end

procedure Jason22
begin
	gsay_reply(SCRIPT_JASON, 146);
	giq_option(4, SCRIPT_JASON, 147, Jason20, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_JASON, 148, Jason21, NEUTRAL_REACTION);
end

procedure Jason23
begin
	gsay_message(SCRIPT_JASON, 149, NEUTRAL_REACTION);
end

procedure follow_player
begin
	if (tile_distance_objs(self_obj, dude_obj) > 7) then begin
		animate_move_obj_to_tile(self_obj, tile_num(dude_obj), ANIMATE_RUN);
	end
	else 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
			animate_move_obj_to_tile(self_obj, tile_num(self_obj), ANIMATE_WALK);
		end
	end
end