#include <define.h>

//#define NAME                    SCRIPT_

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



procedure start;
#include <push.h>
procedure Do_Dialogue;
procedure bob0;
procedure bob1;
procedure bob2;
procedure bob3;
procedure bob4;
procedure bob5;
procedure bob6;
procedure bob7;
procedure bob8;
procedure bob9;
procedure bob10;
procedure bob11;
procedure bob12;
procedure bob13;
procedure bob14;
procedure bob15;
procedure bob16;
procedure bobend;
procedure combat;
procedure damage_p_proc;
procedure destroy_p_proc;

variable Herebefore;
variable Days;
variable Met_Casino;
variable Has_Weapon;


procedure start
begin
	if ((script_action == look_at_proc) or (script_action == description_proc)) then begin
		script_overrides;
		display_msg(message_str(SCRIPT_JTBOB, 100));
	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 == talk_proc) then begin
				call Do_Dialogue;
			end
			else begin
				if (script_action == map_enter_proc) then begin
					if (((game_time / (10 * 60 * 60 * 24)) - Days) >= 7) then begin
						kill_critter(self_obj, 0);
					end
				end
			end
		end
	end
end

procedure Do_Dialogue
begin
	if ((Has_Weapon == 0) and ((obj_item_subtype(critter_inven_obj(dude_obj, 1)) == 3) or (obj_item_subtype(critter_inven_obj(dude_obj, 2)) == 3))) then begin
		Has_Weapon := 1;
		start_gdialog(SCRIPT_JTBOB, self_obj, 4, -1, -1);
		gsay_start;
		call bob0;
		gsay_end;
		end_dialogue;
	end
	else begin
		if (Met_Casino) then begin
			call bob9;
		end
		else begin
			if (Herebefore) then begin
				start_gdialog(SCRIPT_JTBOB, self_obj, 4, -1, -1);
				gsay_start;
				call bob13;
				gsay_end;
				end_dialogue;
			end
			else begin
				Herebefore := 1;
				Days := game_time / (10 * 60 * 60 * 24);
				start_gdialog(SCRIPT_JTBOB, self_obj, 4, -1, -1);
				gsay_start;
				call bob10;
				gsay_end;
				end_dialogue;
			end
		end
	end
end

procedure bob0
begin
	gsay_reply(SCRIPT_JTBOB, 101);
	giq_option(-3, SCRIPT_JTBOB, 102, bob1, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_JTBOB, 103, bob2, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_JTBOB, 104, bob3, NEUTRAL_REACTION);
	giq_option(5, SCRIPT_JTBOB, 105, bob3, NEUTRAL_REACTION);
end

procedure bob1
begin
	gsay_message(SCRIPT_JTBOB, 106, NEUTRAL_REACTION);
end

procedure bob2
begin
	gsay_message(SCRIPT_JTBOB, 107, NEUTRAL_REACTION);
end

procedure bob3
begin
	gsay_reply(SCRIPT_JTBOB, 108);
	giq_option(4, SCRIPT_JTBOB, 109, bob4, NEUTRAL_REACTION);
	giq_option(6, SCRIPT_JTBOB, 110, bob5, NEUTRAL_REACTION);
end

procedure bob4
begin
	if (obj_item_subtype(critter_inven_obj(dude_obj, 1)) == 3) then begin
		gsay_message(SCRIPT_JTBOB, message_str(SCRIPT_JTBOB, 111) + obj_pid(critter_inven_obj(dude_obj, 1)) + message_str(SCRIPT_JTBOB, 112), NEUTRAL_REACTION);
	end
	else begin
		gsay_message(SCRIPT_JTBOB, message_str(SCRIPT_JTBOB, 113) + obj_pid(critter_inven_obj(dude_obj, 2)) + message_str(SCRIPT_JTBOB, 114), NEUTRAL_REACTION);
	end
end

procedure bob5
begin
	gsay_reply(SCRIPT_JTBOB, 115);
	giq_option(6, SCRIPT_JTBOB, 116, bob6, NEUTRAL_REACTION);
	giq_option(6, SCRIPT_JTBOB, 117, bob7, NEUTRAL_REACTION);
	giq_option(6, SCRIPT_JTBOB, 118, bob8, NEUTRAL_REACTION);
	giq_option(6, SCRIPT_JTBOB, 119, bobend, NEUTRAL_REACTION);
end

procedure bob6
begin
	gsay_reply(SCRIPT_JTBOB, 120);
	giq_option(6, SCRIPT_JTBOB, 121, bob7, NEUTRAL_REACTION);
	giq_option(6, SCRIPT_JTBOB, 122, bob8, NEUTRAL_REACTION);
	giq_option(6, SCRIPT_JTBOB, 123, bobend, NEUTRAL_REACTION);
end

procedure bob7
begin
	gsay_reply(SCRIPT_JTBOB, 124);
	giq_option(6, SCRIPT_JTBOB, 125, bob6, NEUTRAL_REACTION);
	giq_option(6, SCRIPT_JTBOB, 126, bob8, NEUTRAL_REACTION);
	giq_option(6, SCRIPT_JTBOB, 127, bobend, NEUTRAL_REACTION);
end

procedure bob8
begin
	gsay_reply(SCRIPT_JTBOB, 128);
	giq_option(6, SCRIPT_JTBOB, 129, bob6, NEUTRAL_REACTION);
	giq_option(6, SCRIPT_JTBOB, 130, bob7, NEUTRAL_REACTION);
	giq_option(6, SCRIPT_JTBOB, 131, bobend, NEUTRAL_REACTION);
end

procedure bob9
begin
	float_msg(self_obj, message_str(SCRIPT_JTBOB, 132), FLOAT_MSG_NORMAL);
end

procedure bob10
begin
	gsay_reply(SCRIPT_JTBOB, 133);
	giq_option(-3, SCRIPT_JTBOB, 134, bob1, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_JTBOB, 135, bob2, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_JTBOB, 136, bob11, NEUTRAL_REACTION);
	giq_option(5, SCRIPT_JTBOB, 137, bob5, NEUTRAL_REACTION);
end

procedure bob11
begin
	gsay_reply(SCRIPT_JTBOB, 138);
	giq_option(4, SCRIPT_JTBOB, 139, bobend, NEUTRAL_REACTION);
	giq_option(6, SCRIPT_JTBOB, 140, bob12, NEUTRAL_REACTION);
end

procedure bob12
begin
	gsay_reply(SCRIPT_JTBOB, 141);
	giq_option(6, SCRIPT_JTBOB, 142, bob6, NEUTRAL_REACTION);
	giq_option(6, SCRIPT_JTBOB, 143, bob7, NEUTRAL_REACTION);
	giq_option(6, SCRIPT_JTBOB, 144, bob8, NEUTRAL_REACTION);
	giq_option(6, SCRIPT_JTBOB, 145, bobend, NEUTRAL_REACTION);
end

procedure bob13
begin
	gsay_reply(SCRIPT_JTBOB, 146);
	giq_option(-3, SCRIPT_JTBOB, 147, bob1, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_JTBOB, 148, bob14, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_JTBOB, 149, bob15, NEUTRAL_REACTION);
	giq_option(6, SCRIPT_JTBOB, 150, bob16, NEUTRAL_REACTION);
end

procedure bob14
begin
	gsay_message(SCRIPT_JTBOB, 151, NEUTRAL_REACTION);
end

procedure bob15
begin
	gsay_message(SCRIPT_JTBOB, 152, NEUTRAL_REACTION);
end

procedure bob16
begin
	gsay_reply(SCRIPT_JTBOB, 153);
	giq_option(6, SCRIPT_JTBOB, 154, bob6, NEUTRAL_REACTION);
	giq_option(6, SCRIPT_JTBOB, 155, bob7, NEUTRAL_REACTION);
	giq_option(6, SCRIPT_JTBOB, 156, bob8, NEUTRAL_REACTION);
	giq_option(6, SCRIPT_JTBOB, 157, bobend, NEUTRAL_REACTION);
end

procedure bobend
begin
end

procedure combat
begin
end

procedure damage_p_proc
begin
	if (source_obj == dude_obj) then begin
		set_global_var(GVAR_ENEMY_JUNKTOWN, 1);
	end
end

procedure destroy_p_proc
begin
	if (source_obj == dude_obj) then begin
		set_global_var(GVAR_ENEMY_JUNKTOWN, 1);
		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
end