#include <define.h>

//#define NAME                    SCRIPT_

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


variable GVar0;
variable GVar1;
variable GVar2;
variable GVar3;
variable GVar4;
variable GVar5;
variable GVar6;
variable GVar7;

procedure start;
#include <push.h>
procedure combat_p_proc;
procedure critter_p_proc;
procedure description_p_proc;
procedure damage_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 Lars00;
procedure Lars01;
procedure Lars02;
procedure Lars03;
procedure Lars04;
procedure Lars05;
procedure Lars06;
procedure Lars07;
procedure Lars08;
procedure Lars09;
procedure Lars10;
procedure Lars11;
procedure Lars12;
procedure Lars13;
procedure Lars14;
procedure Lars15;
procedure Lars16;
procedure Lars17;
procedure Lars18;
procedure Lars19;
procedure Lars20;
procedure Lars21;
procedure Lars22;
procedure Lars23;
procedure Lars24;
procedure Lars25;
procedure Lars26;
procedure Lars27;
procedure LarsEnd;
procedure LarsKillNeal;
procedure Get_Reaction;
procedure React_To_Level;
procedure Level_To_React;
procedure Up_React;
procedure Down_React;
procedure Bottom_React;
procedure Top_React;
procedure Big_Up_React;
procedure Big_Down_React;
procedure Up_React_Level;
procedure Down_React_Level;
procedure Goodbyes;
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 == description_proc) then begin
			call description_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 == map_enter_proc) then begin
						call map_enter_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
end

procedure combat_p_proc
begin
	if (cur_map_index != MAP_JUNKCSNO) then begin
		if (fixed_param == 4) then begin
			GVar2 := GVar2 + 1;
		end
		if (GVar2 > 3) then begin
			if (global_var(GVAR_ENEMY_JUNKTOWN) == 0) then begin
				set_global_var(GVAR_ENEMY_JUNKTOWN, 1);
				set_global_var(GVAR_PLAYER_REPUTATION, global_var(GVAR_PLAYER_REPUTATION) - 5);
			end
		end
	end
end

procedure critter_p_proc
begin
	if (GVar0) then begin
		GVar0 := 0;
		attack_complex(dude_obj, 0, 1, 0, 0, 30000, 0, 0);
	end
	else begin
		if (map_var(0) == 1) then begin
			item_caps_adjust(dude_obj, 500);
			float_msg(self_obj, message_str(SCRIPT_LARS, 162), FLOAT_MSG_GREEN);
			set_map_var(0, 2);
		end
	end
	if (global_var(GVAR_ENEMY_JUNKTOWN) == 1) then begin
		if (obj_can_see_obj(self_obj, dude_obj)) then begin
			attack_complex(dude_obj, 0, 1, 0, 0, 30000, 0, 0);
		end
	end
end

procedure description_p_proc
begin
	if (is_success(do_check(dude_obj, 1, has_trait(0, dude_obj, 0)))) then begin
		display_msg(message_str(SCRIPT_LARS, 103));
	end
	else begin
		display_msg(message_str(SCRIPT_LARS, 102));
	end
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
	if (cur_map_index == MAP_JUNKCSNO) then begin
		script_overrides;
		display_msg(message_str(SCRIPT_LARS, 168));
	end
end

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

procedure map_enter_p_proc
begin
	if (cur_map_index == MAP_JUNKCSNO) then begin
		critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_TEAM_NUM, 0);
	end
	else begin
		critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_TEAM_NUM, 12);
	end
	if ((global_var(GVAR_GIZMO_DEAD) == 1) and (cur_map_index == MAP_JUNKCSNO)) then begin
		destroy_object(self_obj);
	end
end

procedure pickup_p_proc
begin
	float_msg(self_obj, message_str(SCRIPT_LARS, 104), FLOAT_MSG_NORMAL);
	GVar0 := 1;
end

procedure talk_p_proc
begin
	call Get_Reaction;
	start_gdialog(SCRIPT_LARS, self_obj, 4, -1, -1);
	gsay_start;
	if (global_var(GVAR_CHILDKILLER_REPUTATION) > 2) then begin
		call Lars01;
	end
	else begin
		if (global_var(GVAR_ENEMY_JUNKTOWN) == 1) then begin
			call Lars27;
		end
		else begin
			if ((global_var(GVAR_GIZMO_DEAD) == 1) and (global_var(GVAR_CAPTURE_GIZMO) != 2)) then begin
				call Lars26;
			end
			else begin
				if (global_var(GVAR_CAPTURE_GIZMO) == 1) then begin
					set_local_var(4, 1);
					call Lars21;
				end
				else begin
					if (local_var(4) == 0) then begin
						call Lars00;
					end
					else begin
						if (global_var(GVAR_BUST_SKULZ) == 2) then begin
							call Lars19;
						end
						else begin
							call Lars12;
						end
					end
				end
			end
		end
	end
	gsay_end;
	end_dialogue;
	if (GVar5) then begin
		GVar5 := 0;
		load_map(11, 4);
	end
	else begin
		if ((global_var(GVAR_BUST_SKULZ) == 2) and (local_var(5) == 0)) then begin
			set_local_var(5, 1);
			gfade_out(600);
			give_exp_points(500);
			set_global_var(GVAR_PLAYER_REPUTATION, global_var(GVAR_PLAYER_REPUTATION) + 3);
			display_msg(message_str(SCRIPT_LARS, 174));
			game_time_advance(game_ticks(7200));
			gfade_in(600);
		end
		else begin
			if (GVar6) then begin
				gfade_out(600);
				game_time_advance(game_ticks(3000));
				set_global_var(GVAR_CAPTURE_GIZMO, 2);
				gfade_in(600);
				GVar6 := 0;
			end
			else begin
				if (GVar4) then begin
					GVar4 := 0;
					load_map(11, 7);
				end
				else begin
					if (GVar3) then begin
						GVar3 := 0;
						gfade_out(600);
						set_global_var(GVAR_BUST_SKULZ, 2);
						set_global_var(GVAR_DESTROY_VATS_11, 0);
						display_msg(message_str(SCRIPT_LARS, 167));
						gfade_in(600);
					end
				end
			end
		end
	end
end

procedure Lars00
begin
	gsay_reply(SCRIPT_LARS, 105);
	giq_option(4, SCRIPT_LARS, 106, Lars02, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_LARS, 107, Lars05, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_LARS, 108, Lars10, NEUTRAL_REACTION);
	giq_option(-3, SCRIPT_LARS, 109, Lars20, NEUTRAL_REACTION);
	if (global_var(GVAR_BUST_SKULZ) == 1) then begin
		giq_option(6, SCRIPT_LARS, 110, Lars13, NEUTRAL_REACTION);
	end
	if (global_var(GVAR_CAPTURE_GIZMO) == 1) then begin
		giq_option(4, SCRIPT_LARS, 161, Lars22, GOOD_REACTION);
	end
	if (global_var(GVAR_DESTROY_VATS_11) > (game_time / (10 * 60 * 60 * 24))) then begin
		giq_option(4, SCRIPT_LARS, 166, Lars24, GOOD_REACTION);
	end
end

procedure Lars01
begin
	gsay_message(SCRIPT_LARS, 111, BAD_REACTION);
	GVar0 := 1;
end

procedure Lars02
begin
	gsay_reply(SCRIPT_LARS, 112);
	giq_option(4, SCRIPT_LARS, 113, Lars03, NEUTRAL_REACTION);
	call Goodbyes;
	giq_option(4, SCRIPT_LARS, GVar7, LarsEnd, NEUTRAL_REACTION);
end

procedure Lars03
begin
	gsay_reply(SCRIPT_LARS, 114);
	giq_option(4, SCRIPT_LARS, 115, Lars04, NEUTRAL_REACTION);
	call Goodbyes;
	giq_option(4, SCRIPT_LARS, GVar7, LarsEnd, NEUTRAL_REACTION);
end

procedure Lars04
begin
	call Down_React;
	gsay_message(SCRIPT_LARS, 116, BAD_REACTION);
end

procedure Lars05
begin
	gsay_reply(SCRIPT_LARS, 117);
	giq_option(4, SCRIPT_LARS, 118, Lars04, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_LARS, 119, Lars06, NEUTRAL_REACTION);
	giq_option(6, SCRIPT_LARS, 120, Lars07, NEUTRAL_REACTION);
end

procedure Lars06
begin
	gsay_message(SCRIPT_LARS, 121, NEUTRAL_REACTION);
end

procedure Lars07
begin
	gsay_reply(SCRIPT_LARS, 122);
	giq_option(4, SCRIPT_LARS, 123, Lars08, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_LARS, 124, Lars09, NEUTRAL_REACTION);
end

procedure Lars08
begin
	set_global_var(GVAR_BUST_SKULZ, 1);
	gsay_message(SCRIPT_LARS, 125, NEUTRAL_REACTION);
end

procedure Lars09
begin
	gsay_message(SCRIPT_LARS, 126, NEUTRAL_REACTION);
end

procedure Lars10
begin
	variable LVar0 := 0;
	set_local_var(4, 1);
	LVar0 := message_str(SCRIPT_LARS, 128) + proto_data(obj_pid(dude_obj), 1) + message_str(SCRIPT_LARS, 129);
	gsay_reply(SCRIPT_LARS, 127);
	giq_option(4, SCRIPT_LARS, LVar0, Lars11, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_LARS, 130, Lars04, NEUTRAL_REACTION);
	if (global_var(GVAR_CAPTURE_GIZMO) == 1) then begin
		giq_option(4, SCRIPT_LARS, 160, Lars22, GOOD_REACTION);
	end
end

procedure Lars11
begin
	variable LVar0 := 0;
	LVar0 := message_str(SCRIPT_LARS, 131) + proto_data(obj_pid(dude_obj), 1) + message_str(SCRIPT_LARS, 132);
	gsay_reply(SCRIPT_LARS, LVar0);
	giq_option(4, SCRIPT_LARS, 133, Lars05, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_LARS, 134, Lars02, NEUTRAL_REACTION);
	call Goodbyes;
	giq_option(4, SCRIPT_LARS, GVar7, LarsEnd, NEUTRAL_REACTION);
end

procedure Lars12
begin
	if (local_var(1) > 1) then begin
		gsay_reply(SCRIPT_LARS, 135);
	end
	else begin
		if (global_var(GVAR_CAPTURE_GIZMO) == 2) then begin
			gsay_reply(SCRIPT_LARS, 171);
		end
		else begin
			gsay_reply(SCRIPT_LARS, 136);
		end
	end
	if (not(global_var(GVAR_BUST_SKULZ))) then begin
		giq_option(4, SCRIPT_LARS, 137, Lars18, NEUTRAL_REACTION);
	end
	giq_option(4, SCRIPT_LARS, 138, LarsEnd, NEUTRAL_REACTION);
	if (global_var(GVAR_GENERIC_FILLER_20) and (global_var(GVAR_BUST_SKULZ) == 1)) then begin
		giq_option(4, SCRIPT_LARS, 139, Lars14, NEUTRAL_REACTION);
	end
	if (global_var(GVAR_DESTROY_VATS_11) > (game_time / (10 * 60 * 60 * 24))) then begin
		giq_option(4, SCRIPT_LARS, 166, Lars24, GOOD_REACTION);
	end
end

procedure Lars13
begin
	set_local_var(4, 1);
	gsay_reply(SCRIPT_LARS, 140);
	giq_option(4, SCRIPT_LARS, 141, Lars17, NEUTRAL_REACTION);
	if (global_var(GVAR_GENERIC_FILLER_20)) then begin
		giq_option(4, SCRIPT_LARS, 142, Lars16, NEUTRAL_REACTION);
	end
end

procedure Lars14
begin
	gsay_reply(SCRIPT_LARS, 143);
	giq_option(4, SCRIPT_LARS, 144, Lars15, NEUTRAL_REACTION);
	if (global_var(GVAR_GENERIC_FILLER_20)) then begin
		giq_option(4, SCRIPT_LARS, 145, Lars16, NEUTRAL_REACTION);
	end
end

procedure Lars15
begin
	gsay_reply(SCRIPT_LARS, 146);
	giq_option(4, SCRIPT_LARS, 147, LarsEnd, NEUTRAL_REACTION);
	if (global_var(GVAR_GENERIC_FILLER_20)) then begin
		giq_option(4, SCRIPT_LARS, 148, Lars16, NEUTRAL_REACTION);
	end
end

procedure Lars16
begin
	set_global_var(GVAR_BUST_SKULZ, 2);
	gsay_message(SCRIPT_LARS, 149, GOOD_REACTION);
end

procedure Lars17
begin
	call Down_React;
	gsay_message(SCRIPT_LARS, 150, BAD_REACTION);
end

procedure Lars18
begin
	set_global_var(GVAR_BUST_SKULZ, 1);
	gsay_reply(SCRIPT_LARS, 151);
	call Goodbyes;
	giq_option(4, SCRIPT_LARS, GVar7, LarsEnd, NEUTRAL_REACTION);
end

procedure Lars19
begin
	gsay_message(SCRIPT_LARS, 152, NEUTRAL_REACTION);
end

procedure Lars20
begin
	gsay_message(SCRIPT_LARS, 153, NEUTRAL_REACTION);
end

procedure Lars21
begin
	gsay_reply(SCRIPT_LARS, 155);
	giq_option(4, SCRIPT_LARS, 156, Lars22, GOOD_REACTION);
	giq_option(4, SCRIPT_LARS, 157, Lars23, NEUTRAL_REACTION);
	giq_option(-3, SCRIPT_LARS, 172, Lars22, NEUTRAL_REACTION);
	giq_option(-3, SCRIPT_LARS, 173, Lars23, NEUTRAL_REACTION);
end

procedure Lars22
begin
	gsay_message(SCRIPT_LARS, 158, GOOD_REACTION);
	GVar5 := 1;
end

procedure Lars23
begin
	gsay_message(SCRIPT_LARS, 159, NEUTRAL_REACTION);
	GVar6 := 1;
end

procedure Lars24
begin
	set_global_var(GVAR_DESTROY_VATS_15, 1);
	gsay_reply(SCRIPT_LARS, 163);
	giq_option(4, SCRIPT_LARS, 164, Lars25, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_LARS, 165, LarsKillNeal, GOOD_REACTION);
	set_local_var(4, 1);
end

procedure Lars25
begin
	GVar3 := 1;
	set_local_var(5, 1);
end

procedure Lars26
begin
	gsay_message(SCRIPT_LARS, 169, BAD_REACTION);
end

procedure Lars27
begin
	gsay_message(SCRIPT_LARS, 170, BAD_REACTION);
	rm_timer_event(self_obj);
	add_timer_event(self_obj, game_ticks(15), 1);
end

procedure LarsEnd
begin
end

procedure LarsKillNeal
begin
	GVar4 := 1;
end

procedure Get_Reaction
begin
	if (local_var(2) == 0) then begin
		set_local_var(0, 50);
		set_local_var(1, 2);
		set_local_var(2, 1);
		set_local_var(0, local_var(0) + (5 * get_critter_stat(dude_obj, 3)) - 25);
		set_local_var(0, local_var(0) + (10 * has_trait(0, dude_obj, 10)));
		if (has_trait(0, dude_obj, 39)) then begin
			if (global_var(GVAR_PLAYER_REPUTATION) > 0) then begin
				set_local_var(0, local_var(0) + global_var(GVAR_PLAYER_REPUTATION));
			end
			else begin
				set_local_var(0, local_var(0) - global_var(GVAR_PLAYER_REPUTATION));
			end
		end
		else begin
			if (local_var(3) == 1) then begin
				set_local_var(0, local_var(0) - global_var(GVAR_PLAYER_REPUTATION));
			end
			else begin
				set_local_var(0, local_var(0) + global_var(GVAR_PLAYER_REPUTATION));
			end
		end
		if (global_var(GVAR_CHILDKILLER_REPUTATION) > 2) then begin
			set_local_var(0, local_var(0) - 30);
		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_local_var(0, local_var(0) + 20);
		end
		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_local_var(0, local_var(0) - 20);
		end
		call React_To_Level;
	end
end

procedure React_To_Level
begin
	if (local_var(0) <= 25) then begin
		set_local_var(1, 1);
	end
	else begin
		if (local_var(0) <= 75) then begin
			set_local_var(1, 2);
		end
		else begin
			set_local_var(1, 3);
		end
	end
end

procedure Level_To_React
begin
	if (local_var(1) == 1) then begin
		set_local_var(0, random(1, 25));
	end
	else begin
		if (local_var(1) == 2) then begin
			set_local_var(0, random(26, 75));
		end
		else begin
			set_local_var(0, random(76, 100));
		end
	end
end

procedure Up_React
begin
	set_local_var(0, local_var(0) + 10);
	call React_To_Level;
end

procedure Down_React
begin
	set_local_var(0, local_var(0) - 10);
	call React_To_Level;
end

procedure Bottom_React
begin
	set_local_var(1, 1);
	set_local_var(0, 1);
end

procedure Top_React
begin
	set_local_var(0, 100);
	set_local_var(1, 3);
end

procedure Big_Up_React
begin
	set_local_var(0, local_var(0) + 25);
	call React_To_Level;
end

procedure Big_Down_React
begin
	set_local_var(0, local_var(0) - 25);
	call React_To_Level;
end

procedure Up_React_Level
begin
	set_local_var(1, local_var(1) + 1);
	if (local_var(1) > 3) then begin
		set_local_var(1, 3);
	end
	call Level_To_React;
end

procedure Down_React_Level
begin
	set_local_var(1, local_var(1) - 1);
	if (local_var(1) < 1) then begin
		set_local_var(1, 1);
	end
	call Level_To_React;
end

procedure Goodbyes
begin
	GVar7 := message_str(SCRIPT_MODREACT, random(100, 105));
end

procedure timed_event_p_proc
begin
	GVar0 := 1;
end