#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 pickup_p_proc;
procedure talk_p_proc;
procedure Neil00;
procedure Neil01;
procedure Neil02;
procedure Neil03;
procedure Neil04;
procedure Neil05;
procedure Neil06;
procedure Neil07;
procedure Neil08;
procedure Neil09;
procedure Neil10;
procedure Neil11;
procedure Neil12;
procedure Neil13;
procedure Neil14;
procedure Neil15;
procedure Neil16;
procedure Neil16a;
procedure Neil17;
procedure Neil18;
procedure Neil19;
procedure Neil20;
procedure Neil21;
procedure Neil22;
procedure Neil23;
procedure Neil24;
procedure Neil25;
procedure Neil26;
procedure Neil27;
procedure Neil28;
procedure Neil29;
procedure Neil30;
procedure Neil31;
procedure NeilQuest;
procedure NeilCombat;
procedure NeilEnd;

variable hostile1;
variable initialized1;


procedure start
begin
	if (not(initialized1)) then begin
		critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_TEAM_NUM, 46);
		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 == 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
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(4)) then begin
		display_msg(message_str(SCRIPT_NEIL, 100));
	end
	else begin
		display_msg(message_str(SCRIPT_NEIL, 101));
	end
end

procedure pickup_p_proc
begin
	hostile1 := 1;
end

procedure talk_p_proc
begin
	set_local_var(4, 1);
	if ((game_time_hour >= 1900) or (game_time_hour < 600)) then begin
		call Neil00;
	end
	else begin
		if (global_var(GVAR_FIND_AGENT) == 1) then begin
			call Neil27;
		end
		else begin
			if ((global_var(GVAR_FIND_AGENT) == 2) and (local_var(5) == 0)) then begin
				set_local_var(5, 1);
				start_gdialog(SCRIPT_NEIL, self_obj, 4, -1, -1);
				gsay_start;
				call Neil28;
				gsay_end;
				end_dialogue;
			end
			else begin
				if ((global_var(GVAR_TRAIN_FOLLOWERS) == 1) and (local_var(6) == 0)) then begin
					call Neil31;
				end
				else begin
					start_gdialog(SCRIPT_NEIL, self_obj, 4, -1, -1);
					gsay_start;
					call Neil01;
					gsay_end;
					end_dialogue;
				end
			end
		end
	end
end

procedure Neil00
begin
	float_msg(self_obj, message_str(SCRIPT_NEIL, 102), FLOAT_MSG_RED);
end

procedure Neil01
begin
	gsay_reply(SCRIPT_NEIL, 103);
	giq_option(-3, SCRIPT_NEIL, 104, Neil02, NEUTRAL_REACTION);
	giq_option(-3, SCRIPT_NEIL, 105, Neil03, NEUTRAL_REACTION);
	giq_option(-3, SCRIPT_NEIL, 106, NeilCombat, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_NEIL, message_str(SCRIPT_NEIL, 107) + proto_data(obj_pid(dude_obj), 1) + message_str(SCRIPT_NEIL, 108), Neil07, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_NEIL, message_str(SCRIPT_NEIL, 109) + proto_data(obj_pid(dude_obj), 1) + message_str(SCRIPT_NEIL, 110), NeilCombat, NEUTRAL_REACTION);
	giq_option(5, SCRIPT_NEIL, 111, Neil16, NEUTRAL_REACTION);
	giq_option(6, SCRIPT_NEIL, 112, Neil24, NEUTRAL_REACTION);
	giq_option(8, SCRIPT_NEIL, 113, Neil26, NEUTRAL_REACTION);
end

procedure Neil02
begin
	gsay_reply(SCRIPT_NEIL, 114);
	giq_option(0, SCRIPT_NEIL, 115, Neil03, NEUTRAL_REACTION);
	giq_option(0, SCRIPT_NEIL, 116, NeilCombat, NEUTRAL_REACTION);
	giq_option(0, SCRIPT_NEIL, 117, Neil04, NEUTRAL_REACTION);
end

procedure Neil03
begin
	gsay_message(SCRIPT_NEIL, 118, NEUTRAL_REACTION);
end

procedure Neil04
begin
	gsay_reply(SCRIPT_NEIL, 119);
	giq_option(0, SCRIPT_NEIL, 120, Neil05, NEUTRAL_REACTION);
	giq_option(0, SCRIPT_NEIL, 121, Neil06, NEUTRAL_REACTION);
end

procedure Neil05
begin
	gsay_message(SCRIPT_NEIL, 122, NEUTRAL_REACTION);
	set_global_var(GVAR_FIND_AGENT, 1);
end

procedure Neil06
begin
	gsay_message(SCRIPT_NEIL, 123, NEUTRAL_REACTION);
end

procedure Neil07
begin
	gsay_reply(SCRIPT_NEIL, 124);
	giq_option(4, SCRIPT_NEIL, 125, Neil08, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_NEIL, 126, Neil14, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_NEIL, 127, Neil15, NEUTRAL_REACTION);
end

procedure Neil08
begin
	gsay_reply(SCRIPT_NEIL, 128);
	giq_option(4, SCRIPT_NEIL, 129, Neil09, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_NEIL, 130, NeilEnd, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_NEIL, 131, NeilCombat, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_NEIL, 132, Neil13, NEUTRAL_REACTION);
end

procedure Neil09
begin
	gsay_reply(SCRIPT_NEIL, 133);
	giq_option(4, SCRIPT_NEIL, 134, NeilQuest, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_NEIL, 135, Neil10, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_NEIL, 136, Neil13, NEUTRAL_REACTION);
end

procedure Neil10
begin
	gsay_reply(SCRIPT_NEIL, 137);
	giq_option(4, SCRIPT_NEIL, 138, Neil11, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_NEIL, 139, NeilEnd, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_NEIL, 140, NeilCombat, NEUTRAL_REACTION);
end

procedure Neil11
begin
	gsay_reply(SCRIPT_NEIL, 141);
	giq_option(4, SCRIPT_NEIL, 142, Neil12, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_NEIL, 143, Neil13, NEUTRAL_REACTION);
end

procedure Neil12
begin
	gsay_message(SCRIPT_NEIL, 144, NEUTRAL_REACTION);
	call NeilQuest;
end

procedure Neil13
begin
	gsay_message(SCRIPT_NEIL, 145, NEUTRAL_REACTION);
	call NeilCombat;
end

procedure Neil14
begin
	gsay_reply(SCRIPT_NEIL, 146);
	giq_option(4, SCRIPT_NEIL, 147, Neil09, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_NEIL, 148, NeilEnd, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_NEIL, 149, NeilCombat, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_NEIL, 150, Neil13, NEUTRAL_REACTION);
end

procedure Neil15
begin
	gsay_reply(SCRIPT_NEIL, 151);
	giq_option(4, SCRIPT_NEIL, 152, Neil09, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_NEIL, 153, NeilCombat, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_NEIL, 154, Neil13, NEUTRAL_REACTION);
end

procedure Neil16
begin
	gsay_reply(SCRIPT_NEIL, 155);
	giq_option(5, SCRIPT_NEIL, 156, Neil17, NEUTRAL_REACTION);
	giq_option(5, SCRIPT_NEIL, 157, Neil18, NEUTRAL_REACTION);
	giq_option(5, SCRIPT_NEIL, 158, Neil16a, NEUTRAL_REACTION);
end

procedure Neil16a
begin
	if (is_success(roll_vs_skill(dude_obj, 14, 0))) then begin
		call Neil19;
	end
	else begin
		call Neil23;
	end
end

procedure Neil17
begin
	variable LVar0 := 0;
	item_caps_adjust(dude_obj, 200);
	gsay_message(SCRIPT_NEIL, message_str(SCRIPT_NEIL, 159) + " " + message_str(SCRIPT_NEIL, 160), NEUTRAL_REACTION);
	call NeilCombat;
end

procedure Neil18
begin
	gsay_message(SCRIPT_NEIL, 161, NEUTRAL_REACTION);
end

procedure Neil19
begin
	gsay_reply(SCRIPT_NEIL, 162);
	giq_option(5, SCRIPT_NEIL, 163, Neil20, NEUTRAL_REACTION);
	giq_option(5, SCRIPT_NEIL, 164, Neil21, NEUTRAL_REACTION);
	giq_option(5, SCRIPT_NEIL, 165, Neil22, NEUTRAL_REACTION);
	giq_option(5, SCRIPT_NEIL, 166, NeilCombat, NEUTRAL_REACTION);
	giq_option(5, SCRIPT_NEIL, 167, NeilEnd, NEUTRAL_REACTION);
end

procedure Neil20
begin
	gsay_reply(SCRIPT_NEIL, 168);
	giq_option(5, SCRIPT_NEIL, 169, Neil21, NEUTRAL_REACTION);
	giq_option(5, SCRIPT_NEIL, 170, Neil22, NEUTRAL_REACTION);
	giq_option(5, SCRIPT_NEIL, 171, NeilCombat, NEUTRAL_REACTION);
	giq_option(5, SCRIPT_NEIL, 172, NeilEnd, NEUTRAL_REACTION);
end

procedure Neil21
begin
	gsay_reply(SCRIPT_NEIL, 173);
	giq_option(5, SCRIPT_NEIL, 174, Neil20, NEUTRAL_REACTION);
	giq_option(5, SCRIPT_NEIL, 175, Neil22, NEUTRAL_REACTION);
	giq_option(5, SCRIPT_NEIL, 176, NeilCombat, NEUTRAL_REACTION);
	giq_option(5, SCRIPT_NEIL, 177, NeilEnd, NEUTRAL_REACTION);
end

procedure Neil22
begin
	gsay_reply(SCRIPT_NEIL, 178);
	giq_option(5, SCRIPT_NEIL, 179, Neil20, NEUTRAL_REACTION);
	giq_option(5, SCRIPT_NEIL, 180, Neil21, NEUTRAL_REACTION);
	giq_option(5, SCRIPT_NEIL, 181, NeilCombat, NEUTRAL_REACTION);
	giq_option(5, SCRIPT_NEIL, 182, NeilEnd, NEUTRAL_REACTION);
end

procedure Neil23
begin
	gsay_message(SCRIPT_NEIL, 183, NEUTRAL_REACTION);
	call NeilCombat;
end

procedure Neil24
begin
	gsay_reply(SCRIPT_NEIL, 184);
	giq_option(6, SCRIPT_NEIL, 185, Neil08, NEUTRAL_REACTION);
	giq_option(6, SCRIPT_NEIL, 186, Neil14, NEUTRAL_REACTION);
	giq_option(6, SCRIPT_NEIL, 187, Neil25, NEUTRAL_REACTION);
	giq_option(6, SCRIPT_NEIL, 188, NeilEnd, NEUTRAL_REACTION);
end

procedure Neil25
begin
	gsay_message(SCRIPT_NEIL, 189, NEUTRAL_REACTION);
end

procedure Neil26
begin
	gsay_message(SCRIPT_NEIL, 190, NEUTRAL_REACTION);
end

procedure Neil27
begin
	float_msg(self_obj, message_str(SCRIPT_NEIL, 191), FLOAT_MSG_YELLOW);
end

procedure Neil28
begin
	gsay_reply(SCRIPT_NEIL, 192);
	giq_option(4, SCRIPT_NEIL, 193, Neil29, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_NEIL, 194, NeilEnd, NEUTRAL_REACTION);
end

procedure Neil29
begin
	gsay_reply(SCRIPT_NEIL, 195);
	giq_option(4, SCRIPT_NEIL, 196, Neil30, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_NEIL, 197, NeilEnd, NEUTRAL_REACTION);
end

procedure Neil30
begin
	gsay_reply(SCRIPT_NEIL, 198);
	gfade_out(20);
	game_time_advance(game_ticks(24 * 3600));
	set_global_var(GVAR_TRAIN_FOLLOWERS, 1);
	gfade_in(20);
	giq_option(4, SCRIPT_NEIL, 199, Neil31, NEUTRAL_REACTION);
end

procedure Neil31
begin
	float_msg(self_obj, message_str(SCRIPT_NEIL, 200), FLOAT_MSG_YELLOW);
end

procedure NeilQuest
begin
	set_global_var(GVAR_FIND_AGENT, 1);
end

procedure NeilCombat
begin
	hostile1 := 1;
end

procedure NeilEnd
begin
end