#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 map_enter_p_proc;
procedure pickup_p_proc;
procedure talk_p_proc;
procedure Vinnie01;
procedure Vinnie01a;
procedure Vinnie02;
procedure Vinnie03;
procedure Vinnie04;
procedure Vinnie05;
procedure Vinnie06;
procedure Vinnie07;
procedure Vinnie08;
procedure Vinnie09;
procedure Vinnie10;
procedure Vinnie14;
procedure Vinnie14a;
procedure Vinnie15;
procedure Vinnie15a;
procedure Vinnie16;
procedure Vinnie17;
procedure Vinnie18;
procedure Vinnie19;
procedure Vinnie20;
procedure Vinnie21;
procedure Vinnie22;
procedure Vinnie23;
procedure Vinnie24;
procedure Vinnie25;
procedure VinnieEnd;
procedure VinnieCombat;
procedure VinnieKillNeal;

variable hostile1;
variable line160flag;
variable line162flag;
variable Vinnie_kill_Neal;
variable moving_disabled;
variable sleeping_disabled;

import variable Neal_ptr;
import variable removal_ptr;

procedure combat_p_proc;
procedure timed_event_p_proc;


procedure start
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 == map_enter_proc) then begin
				call map_enter_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
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 ((cur_map_index == MAP_JUNKCSNO) and (line160flag == 0)) then begin
			float_msg(self_obj, message_str(SCRIPT_VINNIE, 160), FLOAT_MSG_RED);
			add_timer_event(self_obj, game_ticks(4), 1);
			line160flag := 1;
		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_BAD_MONSTER, global_var(GVAR_BAD_MONSTER) + 1);
		if ((global_var(GVAR_BAD_MONSTER) % 6) == 0) then begin
			set_global_var(GVAR_PLAYER_REPUTATION, global_var(GVAR_PLAYER_REPUTATION) + 1);
		end
	end
	if (cur_map_index == MAP_JUNKCSNO) then begin
		set_map_var(0, map_var(0) - 1);
	end
end

procedure look_at_p_proc
begin
	script_overrides;
	if (local_var(0)) then begin
		display_msg(message_str(SCRIPT_VINNIE, 100));
	end
	else begin
		display_msg(message_str(SCRIPT_VINNIE, 101));
	end
end

procedure map_enter_p_proc
begin
	critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_TEAM_NUM, 14);
	critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_AI_PACKET, AI_SKULZ);
	if ((global_var(GVAR_BUST_SKULZ) == 2) or ((cur_map_index == MAP_JUNKCSNO) and (global_var(GVAR_DESTROY_VATS_12) == 1))) then begin
		move_to(self_obj, 7000, 0);
		set_obj_visibility(self_obj, 1);
		removal_ptr := self_obj;
	end
end

procedure pickup_p_proc
begin
	hostile1 := 1;
end

procedure talk_p_proc
begin
	if (global_var(GVAR_DESTROY_VATS_13) == 2) then begin
		float_msg(self_obj, message_str(SCRIPT_VINNIE, 171), FLOAT_MSG_BLUE);
	end
	else begin
		if (global_var(GVAR_DESTROY_VATS_12) == 1) then begin
			float_msg(self_obj, message_str(SCRIPT_VINNIE, 170), FLOAT_MSG_RED);
		end
		else begin
			start_gdialog(SCRIPT_VINNIE, self_obj, 4, -1, -1);
			gsay_start;
			if (global_var(GVAR_DESTROY_VATS_13) == 1) then begin
				call Vinnie24;
			end
			else begin
				if (local_var(2) == 1) then begin
					call Vinnie19;
				end
				else begin
					if (local_var(0) == 1) then begin
						call Vinnie10;
					end
					else begin
						call Vinnie01;
					end
				end
			end
			gsay_end;
			end_dialogue;
		end
	end
	if (local_var(1) == 1) then begin
		display_msg(message_str(SCRIPT_VINNIE, 163));
		give_exp_points(400);
		set_global_var(GVAR_PLAYER_REPUTATION, global_var(GVAR_PLAYER_REPUTATION) - 1);
		set_local_var(1, 2);
		if (global_var(GVAR_DESTROY_VATS_12) == 0) then begin
			set_global_var(GVAR_DESTROY_VATS_11, (game_time / (10 * 60 * 60 * 24)) + 2);
		end
	end
	if (Vinnie_kill_Neal) then begin
		Vinnie_kill_Neal := 0;
		load_map(11, 7);
	end
	if ((global_var(GVAR_DESTROY_VATS_11) > (game_time / (10 * 60 * 60 * 24))) and (global_var(GVAR_DESTROY_VATS_12) == 0)) then begin
		float_msg(self_obj, message_str(SCRIPT_VINNIE, 159), FLOAT_MSG_BLUE);
	end
end

procedure Vinnie01
begin
	set_local_var(0, 1);
	gsay_reply(SCRIPT_VINNIE, 103);
	giq_option(4, SCRIPT_VINNIE, 104, Vinnie02, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_VINNIE, 105, Vinnie03, NEUTRAL_REACTION);
	if (global_var(GVAR_DESTROY_VATS_10) == 1) then begin
		giq_option(4, SCRIPT_VINNIE, 102, Vinnie01a, NEUTRAL_REACTION);
	end
	giq_option(-3, SCRIPT_VINNIE, 106, Vinnie04, NEUTRAL_REACTION);
end

procedure Vinnie01a
begin
	if (is_success(roll_vs_skill(dude_obj, 14, 0))) then begin
		call Vinnie14;
	end
	else begin
		call Vinnie15;
	end
end

procedure Vinnie02
begin
	gsay_message(SCRIPT_VINNIE, 107, BAD_REACTION);
end

procedure Vinnie03
begin
	gsay_reply(SCRIPT_VINNIE, 108);
	giq_option(4, SCRIPT_VINNIE, 109, VinnieEnd, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_VINNIE, 110, Vinnie06, NEUTRAL_REACTION);
	giq_option(6, SCRIPT_VINNIE, 111, Vinnie05, NEUTRAL_REACTION);
end

procedure Vinnie04
begin
	gsay_message(SCRIPT_VINNIE, 112, NEUTRAL_REACTION);
end

procedure Vinnie05
begin
	gsay_reply(SCRIPT_VINNIE, 113);
	giq_option(4, SCRIPT_VINNIE, 114, VinnieEnd, NEUTRAL_REACTION);
	giq_option(6, SCRIPT_VINNIE, 115, Vinnie07, NEUTRAL_REACTION);
end

procedure Vinnie06
begin
	gsay_message(SCRIPT_VINNIE, 116, BAD_REACTION);
	call VinnieCombat;
end

procedure Vinnie07
begin
	gsay_reply(SCRIPT_VINNIE, 117);
	giq_option(4, SCRIPT_VINNIE, 118, VinnieEnd, NEUTRAL_REACTION);
	giq_option(6, SCRIPT_VINNIE, 119, Vinnie08, NEUTRAL_REACTION);
end

procedure Vinnie08
begin
	gsay_reply(SCRIPT_VINNIE, 120);
	giq_option(4, SCRIPT_VINNIE, 121, VinnieEnd, NEUTRAL_REACTION);
	if (global_var(GVAR_HIRED_BY_GIZMO)) then begin
		giq_option(6, SCRIPT_VINNIE, 122, Vinnie09, NEUTRAL_REACTION);
	end
end

procedure Vinnie09
begin
	gsay_message(SCRIPT_VINNIE, 123, NEUTRAL_REACTION);
end

procedure Vinnie10
begin
	gsay_reply(SCRIPT_VINNIE, 126);
	giq_option(4, SCRIPT_VINNIE, 127, VinnieEnd, NEUTRAL_REACTION);
	if (global_var(GVAR_DESTROY_VATS_10) == 1) then begin
		giq_option(4, SCRIPT_VINNIE, 102, Vinnie01a, NEUTRAL_REACTION);
	end
end

procedure Vinnie14
begin
	gsay_reply(SCRIPT_VINNIE, 131);
	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
		giq_option(4, SCRIPT_VINNIE, 132, VinnieCombat, BAD_REACTION);
	end
	giq_option(4, SCRIPT_VINNIE, 133, Vinnie16, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_VINNIE, 134, Vinnie14a, NEUTRAL_REACTION);
end

procedure Vinnie14a
begin
	if (is_success(roll_vs_skill(dude_obj, 14, 0))) then begin
		call Vinnie16;
	end
	else begin
		call Vinnie15;
	end
end

procedure Vinnie15
begin
	gsay_reply(SCRIPT_VINNIE, 135);
	giq_option(4, SCRIPT_VINNIE, 136, Vinnie15a, NEUTRAL_REACTION);
	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
		giq_option(4, SCRIPT_VINNIE, 137, VinnieCombat, BAD_REACTION);
	end
	giq_option(4, SCRIPT_VINNIE, 138, VinnieEnd, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_VINNIE, 139, Vinnie03, NEUTRAL_REACTION);
end

procedure Vinnie15a
begin
	if (is_success(roll_vs_skill(dude_obj, 14, 0))) then begin
		call Vinnie16;
	end
	else begin
		call Vinnie04;
	end
end

procedure Vinnie16
begin
	gsay_reply(SCRIPT_VINNIE, 140);
	if (global_var(GVAR_DESTROY_VATS_12) == 1) then begin
		giq_option(4, SCRIPT_VINNIE, 145, Vinnie22, GOOD_REACTION);
	end
	else begin
		if (global_var(GVAR_DESTROY_VATS_14) == 1) then begin
			giq_option(4, SCRIPT_VINNIE, 144, Vinnie19, GOOD_REACTION);
		end
		else begin
			giq_option(4, SCRIPT_VINNIE, 141, Vinnie17, NEUTRAL_REACTION);
		end
	end
	giq_option(4, SCRIPT_VINNIE, 142, Vinnie18, BAD_REACTION);
	giq_option(4, SCRIPT_VINNIE, 143, Vinnie04, BAD_REACTION);
end

procedure Vinnie17
begin
	set_local_var(2, 1);
	gsay_message(SCRIPT_VINNIE, 146, GOOD_REACTION);
end

procedure Vinnie18
begin
	gsay_message(SCRIPT_VINNIE, 147, BAD_REACTION);
end

procedure Vinnie19
begin
	gsay_reply(SCRIPT_VINNIE, 148);
	if (obj_is_carrying_obj_pid(dude_obj, 112)) then begin
		giq_option(4, SCRIPT_VINNIE, 149, Vinnie20, GOOD_REACTION);
	end
	else begin
		giq_option(4, SCRIPT_VINNIE, 150, Vinnie21, BAD_REACTION);
	end
	if (global_var(GVAR_DESTROY_VATS_12) == 1) then begin
		giq_option(4, SCRIPT_VINNIE, 151, Vinnie22, GOOD_REACTION);
	end
end

procedure Vinnie20
begin
	set_local_var(2, 0);
	if (local_var(1) == 0) then begin
		set_local_var(1, 1);
	end
	if (global_var(GVAR_DESTROY_VATS_12) == 1) then begin
		call Vinnie22;
	end
	else begin
		set_global_var(GVAR_DESTROY_VATS_11, (game_time / (10 * 60 * 60 * 24)) + 2);
		gsay_reply(SCRIPT_VINNIE, 152);
		giq_option(4, SCRIPT_VINNIE, 153, Vinnie06, BAD_REACTION);
		giq_option(4, SCRIPT_VINNIE, 154, VinnieKillNeal, GOOD_REACTION);
		giq_option(5, SCRIPT_VINNIE, 155, Vinnie23, NEUTRAL_REACTION);
	end
end

procedure Vinnie21
begin
	gsay_message(SCRIPT_VINNIE, 156, BAD_REACTION);
end

procedure Vinnie22
begin
	set_local_var(2, 0);
	set_global_var(GVAR_DESTROY_VATS_13, 2);
	gsay_message(SCRIPT_VINNIE, 157, GOOD_REACTION);
end

procedure Vinnie23
begin
	set_global_var(GVAR_DESTROY_VATS_13, 1);
	gsay_message(SCRIPT_VINNIE, 158, NEUTRAL_REACTION);
end

procedure Vinnie24
begin
	gsay_reply(SCRIPT_VINNIE, 165);
	giq_option(4, SCRIPT_VINNIE, 166, VinnieKillNeal, GOOD_REACTION);
	giq_option(4, SCRIPT_VINNIE, 167, Vinnie23, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_VINNIE, 168, Vinnie25, BAD_REACTION);
end

procedure Vinnie25
begin
	gsay_message(SCRIPT_VINNIE, 169, BAD_REACTION);
	call VinnieCombat;
end

procedure VinnieEnd
begin
end

procedure VinnieCombat
begin
	hostile1 := 1;
end

procedure VinnieKillNeal
begin
	set_global_var(GVAR_DESTROY_VATS_13, 2);
	Vinnie_kill_Neal := 1;
end

procedure combat_p_proc
begin
	if (cur_map_index == MAP_JUNKCSNO) then begin
		if ((map_var(1) != 0) and (line162flag == 0)) then begin
			float_msg(self_obj, message_str(SCRIPT_VINNIE, 162), FLOAT_MSG_RED);
			line162flag := 1;
		end
	end
end

procedure timed_event_p_proc
begin
	if (fixed_param == 1) then begin
		attack_complex(Neal_ptr, 0, 1, 0, 0, 30000, 0, 0);
	end
end