#include <define.h>

//#define NAME                    SCRIPT_

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



procedure start;
#include <push.h>
procedure combat;
procedure critter_p_proc;
procedure pickup_p_proc;
procedure talk_p_proc;
procedure destroy_p_proc;
procedure look_at_p_proc;
procedure timed_event_p_proc;
procedure damage_p_proc;
procedure Keri00;
procedure Keri01;
procedure Keri02;
procedure Keri03;
procedure Keri04;
procedure Keri04a;
procedure Keri04b;
procedure Keri05;
procedure Keri06;
procedure Keri07;
procedure Keri08;
procedure Keri09;
procedure Keri10;
procedure Keri10a;
procedure Keri11;
procedure Keri12;
procedure Keri13;
procedure Keri14;
procedure Keri15;
procedure Keri16;
procedure Keri17;
procedure Keri18;
procedure Keri19;
procedure Keri20;
procedure Keri21a;
procedure Keri21b;
procedure Keri21c;
procedure Keri21d;
procedure Keri27;
procedure Keri28;
procedure Keri29;
procedure Keri30;
procedure Keri33;
procedure Keri34;
procedure KeriEnd;
procedure KeriCombat;
procedure Jailed;
procedure RecalcDate;
procedure RecalcDateString;
procedure SendAroundHouse;

variable hostile1;
variable Only_Once := 1;
variable days;
variable DayString := "None";
variable SetDayNight;
variable Destination;
variable LastMove;

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;

variable exit_line;


procedure start
begin
	if (Only_Once) then begin
		Only_Once := 0;
		critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_TEAM_NUM, 36);
		critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_AI_PACKET, AI_MERCHANT);
		LastMove := 12127;
	end
	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
			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 == timed_event_proc) then begin
							call timed_event_p_proc;
						end
					end
				end
			end
		end
	end
end

procedure combat
begin
	hostile1 := 1;
end

procedure critter_p_proc
begin
	variable LVar0 := 0;
	if (hostile1) then begin
		hostile1 := 0;
		attack_complex(dude_obj, 0, 1, 0, 0, 30000, 0, 0);
	end
	if (SetDayNight == 0) then begin
		add_timer_event(self_obj, game_ticks(random(3, 8)), 1);
		SetDayNight := 1;
	end
	LVar0 := tile_num(self_obj);
	if (LVar0 == 12126) then begin
		if (anim_busy(self_obj) == 0) then begin
			if (has_trait(1, self_obj, 10) != 0) then begin
				anim(self_obj, 1000, 0);
			end
		end
	end
	else begin
		if (LVar0 == 11927) then begin
			if (anim_busy(self_obj) == 0) then begin
				if (has_trait(1, self_obj, 10) != 5) then begin
					anim(self_obj, 1000, 5);
				end
			end
		end
		else begin
			if (LVar0 == 12127) then begin
				if (anim_busy(self_obj) == 0) then begin
					if (has_trait(1, self_obj, 10) != 2) then begin
						anim(self_obj, 1000, 2);
					end
				end
			end
		end
	end
end

procedure pickup_p_proc
begin
	if (local_var(5) == 0) then begin
		dialogue_system_enter;
	end
	else begin
		call Keri10;
	end
end

procedure talk_p_proc
begin
	variable LVar0 := 0;
	call Get_Reaction;
	if (local_var(13) == 1) then begin
		if (local_var(11) < (game_time / (10 * 60 * 60 * 24 * 365))) then begin
			set_local_var(13, 0);
		end
		else begin
			if ((local_var(10) < get_month) or (local_var(10) == 12) and (get_month == 1) and ((local_var(10) != 1) or (get_month != 12))) then begin
				set_local_var(13, 0);
			end
			else begin
				if ((local_var(9) < get_day) and ((local_var(10) != 1) or (get_month != 12))) then begin
					set_local_var(13, 0);
				end
			end
		end
	end
	call RecalcDate;
	LVar0 := local_var(9);
	if ((map_var(24) == 1) and (map_var(28) == 0)) then begin
		call Keri13;
	end
	else begin
		if (local_var(5) == 1) then begin
			call Keri14;
		end
		else begin
			if (map_var(25) == 1) then begin
				call Keri15;
			end
			else begin
				if (map_var(204) == 3) then begin
					start_gdialog(SCRIPT_KERI, self_obj, 4, -1, -1);
					gsay_start;
					call Keri19;
					gsay_end;
					end_dialogue;
				end
				else begin
					if (map_var(26) == 0) then begin
						call Keri00;
					end
					else begin
						if (global_var(GVAR_CC_JOB) == 4) then begin
							start_gdialog(SCRIPT_KERI, self_obj, 4, -1, -1);
							gsay_start;
							call Keri27;
							gsay_end;
							end_dialogue;
						end
						else begin
							if ((map_var(26) == 1) and (local_var(13) == 0)) then begin
								start_gdialog(SCRIPT_KERI, self_obj, 4, -1, -1);
								gsay_start;
								if (local_var(12) == 0) then begin
									call Keri01;
								end
								else begin
									call Keri03;
								end
								gsay_end;
								end_dialogue;
							end
							else begin
								if ((local_var(13) == 1) and (LVar0 == get_day)) then begin
									start_gdialog(SCRIPT_KERI, self_obj, 4, -1, -1);
									gsay_start;
									call Keri28;
									gsay_end;
									end_dialogue;
								end
								else begin
									if ((local_var(13) == 1) and (LVar0 != get_day)) then begin
										start_gdialog(SCRIPT_KERI, self_obj, 4, -1, -1);
										gsay_start;
										call Keri29;
										gsay_end;
										end_dialogue;
									end
								end
							end
						end
					end
				end
			end
		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_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
	set_map_var(28, 1);
end

procedure look_at_p_proc
begin
	script_overrides;
	display_msg(message_str(SCRIPT_KERI, 100));
end

procedure timed_event_p_proc
begin
	call SendAroundHouse;
end

procedure damage_p_proc
begin
	variable LVar0 := 0;
	LVar0 := obj_pid(source_obj);
	if (party_member_obj(LVar0) != 0) then begin
		set_global_var(GVAR_ENEMY_HUB, 1);
	end
end

procedure Keri00
begin
	if (local_var(7) == 0) then begin
		set_local_var(7, 1);
		float_msg(self_obj, message_str(SCRIPT_KERI, 101), FLOAT_MSG_RED);
	end
	else begin
		float_msg(self_obj, message_str(SCRIPT_KERI, 102), FLOAT_MSG_RED);
	end
end

procedure Keri01
begin
	if (global_var(GVAR_JUNKTOWN) == 0) then begin
		set_global_var(GVAR_JUNKTOWN, 1);
	end
	if (global_var(GVAR_BROTHERHOOD_OF_STEEL) == 0) then begin
		set_global_var(GVAR_BROTHERHOOD_OF_STEEL, 1);
	end
	if (global_var(GVAR_NECROPOLIS) == 0) then begin
		set_global_var(GVAR_NECROPOLIS, 1);
	end
	if (global_var(GVAR_ANGELS_BONEYARD) == 0) then begin
		set_global_var(GVAR_ANGELS_BONEYARD, 1);
	end
	if (dude_is_female) then begin
		gsay_reply(SCRIPT_KERI, 103);
	end
	else begin
		gsay_reply(SCRIPT_KERI, 104);
	end
	giq_option(4, SCRIPT_KERI, 105, Keri02, NEUTRAL_REACTION);
	giq_option(-3, SCRIPT_KERI, 106, Keri02, NEUTRAL_REACTION);
end

procedure Keri02
begin
	variable LVar0 := 0;
	call RecalcDateString;
	LVar0 := local_var(9);
	if (LVar0 == get_day) then begin
		gsay_reply(SCRIPT_KERI, message_str(SCRIPT_KERI, 107) + message_str(SCRIPT_KERI, 108));
	end
	else begin
		gsay_reply(SCRIPT_KERI, message_str(SCRIPT_KERI, 107) + message_str(SCRIPT_KERI, 109) + DayString + message_str(SCRIPT_KERI, 112));
	end
	call Keri04;
end

procedure Keri03
begin
	variable LVar0 := 0;
	if (local_var(1) != 1) then begin
		call RecalcDateString;
		LVar0 := local_var(9);
		if (LVar0 == get_day) then begin
			gsay_reply(SCRIPT_KERI, message_str(SCRIPT_KERI, 113));
		end
		else begin
			gsay_reply(SCRIPT_KERI, message_str(SCRIPT_KERI, 114) + DayString + message_str(SCRIPT_KERI, 117));
		end
		call Keri04;
	end
	else begin
		gsay_reply(SCRIPT_KERI, 118);
		call Keri04;
	end
end

procedure Keri04
begin
	giq_option(4, SCRIPT_KERI, 119, Keri04a, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_KERI, 120, Keri05, NEUTRAL_REACTION);
	if ((dude_is_male) and (local_var(14) == 0)) then begin
		giq_option(4, SCRIPT_KERI, 121, Keri04b, NEUTRAL_REACTION);
	end
	giq_option(4, SCRIPT_KERI, 122, Keri06, NEUTRAL_REACTION);
	giq_option(-3, SCRIPT_KERI, 123, Keri07, NEUTRAL_REACTION);
end

procedure Keri04a
begin
	variable LVar0 := 0;
	set_local_var(13, 1);
	call RecalcDate;
	LVar0 := local_var(9);
	if (LVar0 == get_day) then begin
		call Keri17;
	end
	else begin
		call Keri18;
	end
end

procedure Keri04b
begin
	variable LVar0 := 0;
	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
		call Keri08;
	end
	else begin
		LVar0 := get_critter_stat(dude_obj, 3);
		if (LVar0 <= 6) then begin
			call Keri16;
		end
		else begin
			if (is_success(do_check(dude_obj, 3, 0))) then begin
				call Keri09;
			end
			else begin
				call Keri16;
			end
		end
	end
end

procedure Keri05
begin
	set_local_var(13, 0);
	gsay_message(SCRIPT_KERI, 124, NEUTRAL_REACTION);
end

procedure Keri06
begin
	set_local_var(13, 0);
	gsay_message(SCRIPT_KERI, 126, NEUTRAL_REACTION);
end

procedure Keri07
begin
	gsay_message(SCRIPT_KERI, 127, NEUTRAL_REACTION);
end

procedure Keri08
begin
	variable LVar0 := 0;
	set_local_var(14, 1);
	gsay_message(SCRIPT_KERI, 130, NEUTRAL_REACTION);
	gfade_out(600);
	game_time_advance(game_ticks(60 * 60 * 2));
	gfade_in(600);
	LVar0 := create_object_sid(53, 0, 0, -1);
	add_obj_to_inven(dude_obj, LVar0);
	LVar0 := create_object_sid(87, 0, 0, -1);
	add_obj_to_inven(dude_obj, LVar0);
	LVar0 := create_object_sid(110, 0, 0, -1);
	add_obj_to_inven(dude_obj, LVar0);
	display_msg(message_str(SCRIPT_KERI, 229));
	gsay_message(SCRIPT_KERI, 131, NEUTRAL_REACTION);
	gsay_message(SCRIPT_KERI, 132, NEUTRAL_REACTION);
end

procedure Keri09
begin
	variable LVar0 := 0;
	set_local_var(14, 1);
	gsay_message(SCRIPT_KERI, 133, NEUTRAL_REACTION);
	gfade_out(600);
	game_time_advance(game_ticks(60 * 60 * 2));
	gfade_in(600);
	LVar0 := create_object_sid(53, 0, 0, -1);
	add_obj_to_inven(dude_obj, LVar0);
	LVar0 := create_object_sid(87, 0, 0, -1);
	add_obj_to_inven(dude_obj, LVar0);
	LVar0 := create_object_sid(110, 0, 0, -1);
	add_obj_to_inven(dude_obj, LVar0);
	display_msg(message_str(SCRIPT_KERI, 229));
	gsay_message(SCRIPT_KERI, 131, NEUTRAL_REACTION);
	gsay_message(SCRIPT_KERI, 132, NEUTRAL_REACTION);
end

procedure Keri10
begin
	if (local_var(5) == 0) then begin
		set_local_var(5, 1);
		set_map_var(25, 1);
		gsay_reply(SCRIPT_KERI, 136);
		giq_option(4, SCRIPT_KERI, 137, Keri10a, NEUTRAL_REACTION);
		giq_option(4, SCRIPT_KERI, 138, KeriCombat, BAD_REACTION);
		giq_option(4, SCRIPT_KERI, 139, KeriCombat, BAD_REACTION);
		giq_option(-3, SCRIPT_KERI, 141, KeriCombat, BAD_REACTION);
	end
	else begin
		if (dude_is_male) then begin
			float_msg(self_obj, message_str(SCRIPT_KERI, 143), FLOAT_MSG_RED);
		end
		else begin
			float_msg(self_obj, message_str(SCRIPT_KERI, 142), FLOAT_MSG_RED);
		end
		call KeriCombat;
	end
end

procedure Keri10a
begin
	if (is_success(roll_vs_skill(dude_obj, 14, -20))) then begin
		call Keri11;
	end
	else begin
		call Keri12;
	end
end

procedure Keri11
begin
	gsay_message(SCRIPT_KERI, 144, NEUTRAL_REACTION);
end

procedure Keri12
begin
	gsay_reply(SCRIPT_KERI, 145);
	call KeriCombat;
end

procedure Keri13
begin
	float_msg(self_obj, message_str(SCRIPT_KERI, 148), FLOAT_MSG_RED);
	call KeriCombat;
end

procedure Keri14
begin
	float_msg(self_obj, message_str(SCRIPT_KERI, random(149, 150)), FLOAT_MSG_RED);
	call KeriCombat;
end

procedure Keri15
begin
	if (local_var(6) != 3) then begin
		float_msg(self_obj, message_str(SCRIPT_KERI, 151 + local_var(6)), FLOAT_MSG_RED);
		set_local_var(6, local_var(6) + 1);
	end
	else begin
		float_msg(self_obj, message_str(SCRIPT_KERI, 154), FLOAT_MSG_RED);
	end
end

procedure Keri16
begin
	gsay_message(SCRIPT_KERI, 155, NEUTRAL_REACTION);
end

procedure Keri17
begin
	gsay_reply(SCRIPT_KERI, 156);
	call Keri33;
	call Keri20;
end

procedure Keri18
begin
	call RecalcDateString;
	gsay_reply(SCRIPT_KERI, message_str(SCRIPT_KERI, 157) + DayString + message_str(SCRIPT_KERI, 158));
	giq_option(4, SCRIPT_KERI, 159, Keri30, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_KERI, 160, Keri34, NEUTRAL_REACTION);
end

procedure Keri19
begin
	set_map_var(25, 1);
	set_global_var(GVAR_CC_JOB, 0);
	if (dude_is_female) then begin
		float_msg(self_obj, message_str(SCRIPT_KERI, 161), FLOAT_MSG_RED);
	end
	else begin
		float_msg(self_obj, message_str(SCRIPT_KERI, 162), FLOAT_MSG_RED);
	end
end

procedure Keri20
begin
	giq_option(4, SCRIPT_KERI, 163, Keri21a, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_KERI, 164, Keri21b, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_KERI, 165, Keri21c, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_KERI, 166, Keri21d, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_KERI, 167, Keri34, NEUTRAL_REACTION);
end

procedure Keri21a
begin
	variable LVar0 := 0;
	set_global_var(GVAR_CRIMSON_CARAVANS_STATUS, 1);
	LVar0 := random(1, 8);
	if (LVar0 == 1) then begin
		gsay_message(SCRIPT_KERI, 168, NEUTRAL_REACTION);
	end
	else begin
		if (LVar0 == 2) then begin
			gsay_message(SCRIPT_KERI, 169, NEUTRAL_REACTION);
		end
		else begin
			if (LVar0 == 3) then begin
				gsay_message(SCRIPT_KERI, 170, NEUTRAL_REACTION);
			end
			else begin
				if (LVar0 == 4) then begin
					gsay_message(SCRIPT_KERI, 171, NEUTRAL_REACTION);
				end
				else begin
					if (LVar0 == 5) then begin
						gsay_message(SCRIPT_KERI, 172, NEUTRAL_REACTION);
					end
					else begin
						if (LVar0 == 6) then begin
							gsay_message(SCRIPT_KERI, 173, NEUTRAL_REACTION);
						end
						else begin
							if (LVar0 == 7) then begin
								gsay_message(SCRIPT_KERI, 174, NEUTRAL_REACTION);
							end
							else begin
								if (LVar0 == 8) then begin
									gsay_message(SCRIPT_KERI, 175, NEUTRAL_REACTION);
								end
							end
						end
					end
				end
			end
		end
	end
	load_map(59, 3);
end

procedure Keri21b
begin
	variable LVar0 := 0;
	set_global_var(GVAR_CRIMSON_CARAVANS_STATUS, 1);
	LVar0 := random(1, 7);
	if (LVar0 == 1) then begin
		gsay_message(SCRIPT_KERI, 168, NEUTRAL_REACTION);
	end
	else begin
		if (LVar0 == 2) then begin
			gsay_message(SCRIPT_KERI, 169, NEUTRAL_REACTION);
		end
		else begin
			if (LVar0 == 3) then begin
				gsay_message(SCRIPT_KERI, 170, NEUTRAL_REACTION);
			end
			else begin
				if (LVar0 == 4) then begin
					gsay_message(SCRIPT_KERI, 171, NEUTRAL_REACTION);
				end
				else begin
					if (LVar0 == 5) then begin
						gsay_message(SCRIPT_KERI, 176, NEUTRAL_REACTION);
					end
					else begin
						if (LVar0 == 6) then begin
							gsay_message(SCRIPT_KERI, 177, NEUTRAL_REACTION);
						end
						else begin
							if (LVar0 == 7) then begin
								gsay_message(SCRIPT_KERI, 178, NEUTRAL_REACTION);
							end
						end
					end
				end
			end
		end
	end
	LVar0 := random(1, 4);
	load_map(58, 3);
end

procedure Keri21c
begin
	variable LVar0 := 0;
	set_global_var(GVAR_CRIMSON_CARAVANS_STATUS, 1);
	LVar0 := random(1, 7);
	if (LVar0 == 1) then begin
		gsay_message(SCRIPT_KERI, 168, NEUTRAL_REACTION);
	end
	else begin
		if (LVar0 == 2) then begin
			gsay_message(SCRIPT_KERI, 169, NEUTRAL_REACTION);
		end
		else begin
			if (LVar0 == 3) then begin
				gsay_message(SCRIPT_KERI, 170, NEUTRAL_REACTION);
			end
			else begin
				if (LVar0 == 4) then begin
					gsay_message(SCRIPT_KERI, 171, NEUTRAL_REACTION);
				end
				else begin
					if (LVar0 == 5) then begin
						gsay_message(SCRIPT_KERI, 179, NEUTRAL_REACTION);
					end
					else begin
						if (LVar0 == 6) then begin
							gsay_message(SCRIPT_KERI, 180, NEUTRAL_REACTION);
						end
						else begin
							if (LVar0 == 7) then begin
								gsay_message(SCRIPT_KERI, 181, NEUTRAL_REACTION);
							end
						end
					end
				end
			end
		end
	end
	load_map(57, 3);
end

procedure Keri21d
begin
	variable LVar0 := 0;
	set_global_var(GVAR_CRIMSON_CARAVANS_STATUS, 1);
	LVar0 := random(1, 7);
	if (LVar0 == 1) then begin
		gsay_message(SCRIPT_KERI, 168, NEUTRAL_REACTION);
	end
	else begin
		if (LVar0 == 2) then begin
			gsay_message(SCRIPT_KERI, 169, NEUTRAL_REACTION);
		end
		else begin
			if (LVar0 == 3) then begin
				gsay_message(SCRIPT_KERI, 170, NEUTRAL_REACTION);
			end
			else begin
				if (LVar0 == 4) then begin
					gsay_message(SCRIPT_KERI, 171, NEUTRAL_REACTION);
				end
				else begin
					if (LVar0 == 5) then begin
						gsay_message(SCRIPT_KERI, 182, NEUTRAL_REACTION);
					end
					else begin
						if (LVar0 == 6) then begin
							gsay_message(SCRIPT_KERI, 183, NEUTRAL_REACTION);
						end
						else begin
							if (LVar0 == 7) then begin
								gsay_message(SCRIPT_KERI, 184, NEUTRAL_REACTION);
							end
						end
					end
				end
			end
		end
	end
	load_map(56, 3);
end

procedure Keri27
begin
	gsay_reply(SCRIPT_KERI, 198);
	giq_option(4, SCRIPT_KERI, 199, Keri04a, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_KERI, 200, Keri05, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_KERI, 201, Keri06, NEUTRAL_REACTION);
	giq_option(-3, SCRIPT_KERI, 202, Keri07, NEUTRAL_REACTION);
	giq_option(-3, SCRIPT_KERI, 203, Keri07, NEUTRAL_REACTION);
end

procedure Keri28
begin
	gsay_reply(SCRIPT_KERI, 204);
	giq_option(4, SCRIPT_KERI, 205, Keri17, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_KERI, 206, KeriEnd, NEUTRAL_REACTION);
	giq_option(-3, SCRIPT_KERI, 207, Keri07, NEUTRAL_REACTION);
end

procedure Keri29
begin
	variable LVar0 := 0;
	call RecalcDateString;
	LVar0 := local_var(9);
	gsay_message(SCRIPT_KERI, message_str(SCRIPT_KERI, 209) + DayString + message_str(SCRIPT_KERI, 212), NEUTRAL_REACTION);
end

procedure Keri30
begin
	set_local_var(13, 1);
end

procedure Keri33
begin
	variable LVar0 := 0;
	set_local_var(13, 0);
	set_global_var(GVAR_CC_JOB, 1);
	LVar0 := local_var(12);
	set_local_var(12, LVar0 + 1);
end

procedure Keri34
begin
	set_local_var(13, 0);
end

procedure KeriEnd
begin
end

procedure KeriCombat
begin
	set_map_var(24, 1);
	set_map_var(25, 1);
	call combat;
end

procedure Jailed
begin
	set_map_var(25, 1);
	gfade_out(600);
	move_to(dude_obj, 21867, 0);
	gfade_in(600);
end

procedure RecalcDate
begin
	variable LVar0 := 0;
	variable LVar1 := 0;
	variable LVar2 := 0;
	LVar0 := get_day;
	if (LVar0 <= 3) then begin
		LVar0 := 3;
		LVar1 := get_month;
		LVar2 := game_time / (10 * 60 * 60 * 24 * 365);
	end
	else begin
		if ((LVar0 > 3) and (LVar0 <= 17)) then begin
			LVar0 := 17;
			LVar1 := get_month;
			LVar2 := game_time / (10 * 60 * 60 * 24 * 365);
		end
		else begin
			if (LVar0 > 17) then begin
				LVar0 := 3;
				LVar1 := get_month;
				if (LVar1 == 12) then begin
					LVar1 := 1;
					LVar2 := (game_time / (10 * 60 * 60 * 24 * 365)) + 1;
				end
				else begin
					LVar1 := LVar1 + 1;
					LVar2 := game_time / (10 * 60 * 60 * 24 * 365);
				end
			end
		end
	end
	set_local_var(9, LVar0);
	set_local_var(10, LVar1);
	set_local_var(11, LVar2);
end

procedure RecalcDateString
begin
	variable LVar0 := 0;
	variable LVar1 := 0;
	call RecalcDate;
	LVar0 := local_var(10);
	LVar1 := local_var(9);
	if (LVar0 == 1) then begin
		DayString := message_str(SCRIPT_KERI, 217);
	end
	else begin
		if (LVar0 == 2) then begin
			DayString := message_str(SCRIPT_KERI, 218);
		end
		else begin
			if (LVar0 == 3) then begin
				DayString := message_str(SCRIPT_KERI, 219);
			end
			else begin
				if (LVar0 == 4) then begin
					DayString := message_str(SCRIPT_KERI, 220);
				end
				else begin
					if (LVar0 == 5) then begin
						DayString := message_str(SCRIPT_KERI, 221);
					end
					else begin
						if (LVar0 == 6) then begin
							DayString := message_str(SCRIPT_KERI, 222);
						end
						else begin
							if (LVar0 == 7) then begin
								DayString := message_str(SCRIPT_KERI, 223);
							end
							else begin
								if (LVar0 == 8) then begin
									DayString := message_str(SCRIPT_KERI, 224);
								end
								else begin
									if (LVar0 == 9) then begin
										DayString := message_str(SCRIPT_KERI, 225);
									end
									else begin
										if (LVar0 == 10) then begin
											DayString := message_str(SCRIPT_KERI, 226);
										end
										else begin
											if (LVar0 == 11) then begin
												DayString := message_str(SCRIPT_KERI, 227);
											end
											else begin
												if (LVar0 == 12) then begin
													DayString := message_str(SCRIPT_KERI, 228);
												end
											end
										end
									end
								end
							end
						end
					end
				end
			end
		end
	end
	if (LVar1 == 3) then begin
		DayString := DayString + message_str(SCRIPT_KERI, 210);
	end
	else begin
		if (LVar1 == 17) then begin
			DayString := DayString + message_str(SCRIPT_KERI, 211);
		end
	end
end

procedure SendAroundHouse
begin
	variable LVar0 := 0;
	Destination := 0;
	LVar0 := random(10, 20);
	while(Destination == 0) do begin
		Destination := random(1, 3);
		if (Destination == 1) then begin
			Destination := 12127;
		end
		else begin
			if (Destination == 2) then begin
				Destination := 12126;
			end
			else begin
				if (Destination == 3) then begin
					Destination := 11927;
				end
			end
		end
		if (Destination == LastMove) then begin
			Destination := 0;
		end
	end
	LastMove := Destination;
	reg_anim_func(2, self_obj);
	reg_anim_func(1, 1);
	reg_anim_obj_move_to_tile(self_obj, Destination, -1);
	reg_anim_func(3, 0);
	rm_timer_event(self_obj);
	add_timer_event(self_obj, game_ticks(LVar0), 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
	exit_line := message_str(SCRIPT_MODREACT, random(100, 105));
end