#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;
variable GVar8;
variable GVar9;
variable GVar10;
variable GVar11;
variable GVar12;
variable GVar13;
variable GVar14;

procedure start;
#include <push.h>
procedure critter_p_proc;
procedure look_at_p_proc;
procedure map_enter_p_proc;
procedure map_update_p_proc;
procedure pickup_p_proc;
procedure talk_p_proc;
procedure timed_event_p_proc;
procedure destroy_p_proc;
procedure Morbid00;
procedure Morbid00a;
procedure Morbid01;
procedure Morbid02;
procedure Morbid03;
procedure Morbid04;
procedure Morbid04a;
procedure Morbid05;
procedure Morbid05a;
procedure Morbid06;
procedure Morbid07;
procedure Morbid08;
procedure Morbid09;
procedure Morbid09a;
procedure Morbid10;
procedure Morbid11;
procedure Morbid12;
procedure Morbid13;
procedure Morbid14;
procedure Morbid15;
procedure Morbid16;
procedure Morbid17;
procedure Morbid18;
procedure Morbid19;
procedure Morbid20;
procedure Morbid21;
procedure Morbid22;
procedure Morbid23;
procedure Morbid24;
procedure Morbid25;
procedure Morbid26;
procedure Morbid27;
procedure Morbid28;
procedure Morbid00L;
procedure Morbid00La;
procedure Morbid01L;
procedure Morbid02L;
procedure Morbid02La;
procedure Morbid03L;
procedure Morbid04L;
procedure Morbid05L;
procedure Morbid06L;
procedure Morbid07L;
procedure Morbid08L;
procedure Morbid09L;
procedure Morbid10L;
procedure Morbid00N;
procedure Morbid00Na;
procedure Morbid00Nb;
procedure Morbid01N;
procedure Morbid02N;
procedure Morbid03N;
procedure Morbid04N;
procedure get_eye;
procedure MorbidCombat;
procedure MorbidEnd;
procedure sleeping;

import variable fetch_dude;
import variable Morbid_ptr;
import variable ladder_down;
import variable Gretch_call;

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 combat_p_proc;
procedure damage_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 == 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 == map_update_proc) then begin
						call map_update_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 == timed_event_proc) then begin
									call timed_event_p_proc;
								end
							end
						end
					end
				end
			end
		end
	end
end

procedure critter_p_proc
begin
	if (GVar5) then begin
		GVar5 := 0;
		attack_complex(dude_obj, 0, 1, 0, 0, 30000, 0, 0);
	end
	else begin
		if (GVar11) then begin
			call get_eye;
		end
		else begin
			if ((game_time_hour > 2000) and (game_time_hour < 2330)) then begin
				if (elevation(self_obj) != 1) then begin
					use_obj(ladder_down);
				end
				else begin
					if (tile_num(self_obj) != 12702) then begin
						animate_move_obj_to_tile(self_obj, 12702, ANIMATE_WALK);
					end
				end
			end
			else begin
				call sleeping;
			end
		end
	end
	if (global_var(GVAR_CURE_JARVIS_7) == 1) then begin
		if (obj_can_see_obj(self_obj, dude_obj)) then begin
			if (GVar13 == 0) then begin
				GVar5 := 1;
				GVar13 := 1;
			end
		end
	end
end

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

procedure map_enter_p_proc
begin
	critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_TEAM_NUM, 19);
	Morbid_ptr := self_obj;
	GVar2 := 2340;
	GVar1 := 810;
	GVar3 := 13501;
	GVar4 := 14098;
	if (combat_is_initialized == 0) then begin
		call sleeping;
		if ((game_time_hour > 1700) and (game_time_hour < 2330)) then begin
			move_to(self_obj, 12702, 1);
		end
		else begin
			if ((game_time_hour >= 2330) or (game_time_hour < 800)) then begin
				move_to(self_obj, GVar4, 1);
			end
			else begin
				move_to(self_obj, GVar3, 0);
			end
		end
	end
	rm_timer_event(self_obj);
	add_timer_event(self_obj, game_ticks(random(10, 30)), 2);
end

procedure map_update_p_proc
begin
	if (combat_is_initialized == 0) then begin
		if ((game_time_hour > 1700) and (game_time_hour < 2330)) then begin
			move_to(self_obj, 12702, 1);
		end
		else begin
			if ((game_time_hour >= 2330) or (game_time_hour < 800)) then begin
				move_to(self_obj, GVar4, 1);
			end
			else begin
				move_to(self_obj, GVar3, 0);
			end
		end
	end
end

procedure pickup_p_proc
begin
	GVar5 := 1;
end

procedure talk_p_proc
begin
	if (local_var(6) == 1) then begin
		display_msg(message_str(SCRIPT_MORBID, 232));
	end
	else begin
		if (local_var(9) == 1) then begin
			float_msg(self_obj, message_str(SCRIPT_ENEMY, 101), FLOAT_MSG_RED);
		end
		else begin
			call Get_Reaction;
			start_gdialog(SCRIPT_MORBID, self_obj, 4, -1, -1);
			gsay_start;
			if (GVar12) then begin
				call Morbid09L;
			end
			else begin
				if (elevation(self_obj) == 1) then begin
					if (not(local_var(5))) then begin
						call Morbid00L;
					end
					else begin
						call Morbid01L;
					end
				end
				else begin
					if ((game_time / (10 * 60 * 60 * 24)) >= 80) then begin
						if (not(local_var(7))) then begin
							call Morbid17;
						end
						else begin
							call Morbid21;
						end
					end
					else begin
						if ((game_time_hour >= 1900) or (game_time_hour < 600)) then begin
							if (local_var(4)) then begin
								call Morbid04N;
							end
							else begin
								call Morbid00N;
							end
						end
						else begin
							if (local_var(4)) then begin
								if (local_var(1) > 1) then begin
									call Morbid13;
								end
								else begin
									call Morbid16;
								end
							end
							else begin
								if (local_var(1) > 1) then begin
									call Morbid00;
								end
								else begin
									call Morbid15;
								end
							end
						end
					end
				end
			end
			gsay_end;
			end_dialogue;
		end
	end
end

procedure timed_event_p_proc
begin
	if (fixed_param == 1) then begin
		critter_injure(dude_obj, 64);
		game_ui_enable;
		GVar12 := 1;
		dialogue_system_enter;
		add_timer_event(self_obj, game_ticks(random(10, 30)), 2);
	end
	else begin
		if (fixed_param == 2) then begin
			if ((elevation(self_obj) == 1) and (game_time_hour > 1700) and (game_time_hour < 2330)) then begin
				reg_anim_func(2, self_obj);
				reg_anim_func(1, 1);
				reg_anim_animate(self_obj, 11, -1);
				reg_anim_obj_move_to_tile(self_obj, 12901, -1);
				reg_anim_animate(self_obj, 10, -1);
				reg_anim_obj_move_to_tile(self_obj, 12702, -1);
				reg_anim_func(3, 0);
			end
			add_timer_event(self_obj, game_ticks(random(10, 30)), 2);
		end
	end
end

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

procedure Morbid00
begin
	set_local_var(4, 1);
	gsay_reply(SCRIPT_MORBID, 101);
	giq_option(4, SCRIPT_MORBID, 102, Morbid03, NEUTRAL_REACTION);
	giq_option(5, SCRIPT_MORBID, 103, Morbid03, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_MORBID, 104, Morbid02, NEUTRAL_REACTION);
	giq_option(-3, SCRIPT_MORBID, 105, Morbid00a, BAD_REACTION);
	giq_option(-3, SCRIPT_MORBID, 106, Morbid03, NEUTRAL_REACTION);
	if ((global_var(GVAR_DESTROY_MASTER_1) == 1) and (local_var(8) == 0)) then begin
		giq_option(4, SCRIPT_MORBID, 233, Morbid27, BAD_REACTION);
	end
end

procedure Morbid00a
begin
	call Down_React;
	call Morbid01;
end

procedure Morbid01
begin
	gsay_message(SCRIPT_MORBID, 107, NEUTRAL_REACTION);
end

procedure Morbid02
begin
	gsay_reply(SCRIPT_MORBID, 108);
	giq_option(4, SCRIPT_MORBID, 109, MorbidEnd, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_MORBID, 110, Down_React, BAD_REACTION);
end

procedure Morbid03
begin
	gsay_message(SCRIPT_MORBID, 111, NEUTRAL_REACTION);
	if ((get_critter_stat(dude_obj, 35) == get_critter_stat(dude_obj, 7)) and not(get_poison(dude_obj)) and (get_critter_stat(dude_obj, 37) < 31)) then begin
		call Morbid04;
	end
	else begin
		call Morbid09;
	end
end

procedure Morbid04
begin
	gsay_reply(SCRIPT_MORBID, 112);
	giq_option(4, SCRIPT_MORBID, 113, Morbid04a, BAD_REACTION);
	giq_option(4, SCRIPT_MORBID, 114, Morbid07, NEUTRAL_REACTION);
end

procedure Morbid04a
begin
	call Down_React;
	call Down_React;
	call Morbid05;
end

procedure Morbid05
begin
	gsay_reply(SCRIPT_MORBID, 115);
	giq_option(4, SCRIPT_MORBID, 116, Morbid07, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_MORBID, 117, Morbid05a, BAD_REACTION);
end

procedure Morbid05a
begin
	call Down_React;
	call Down_React;
	call Morbid06;
end

procedure Morbid06
begin
	fetch_dude := 1;
	gsay_message(SCRIPT_MORBID, 118, NEUTRAL_REACTION);
end

procedure Morbid07
begin
	if (item_caps_total(dude_obj) < 10) then begin
		call Morbid08;
	end
	else begin
		item_caps_adjust(dude_obj, -10);
		gsay_message(SCRIPT_MORBID, 119, NEUTRAL_REACTION);
	end
end

procedure Morbid08
begin
	fetch_dude := 1;
	gsay_message(SCRIPT_MORBID, 120, NEUTRAL_REACTION);
end

procedure Morbid09
begin
	variable LVar0 := 0;
	gsay_message(SCRIPT_MORBID, 121, NEUTRAL_REACTION);
	GVar9 := message_str(SCRIPT_MORBID, 122);
	if (get_critter_stat(dude_obj, 35) == get_critter_stat(dude_obj, 7)) then begin
		GVar9 := GVar9 + message_str(SCRIPT_MORBID, 178);
	end
	else begin
		if (get_critter_stat(dude_obj, 35) > (get_critter_stat(dude_obj, 7) * 0.70000)) then begin
			GVar9 := GVar9 + message_str(SCRIPT_MORBID, 179);
		end
		else begin
			if (get_critter_stat(dude_obj, 35) > (get_critter_stat(dude_obj, 7) * 0.50000)) then begin
				GVar9 := GVar9 + message_str(SCRIPT_MORBID, 180);
			end
			else begin
				if (get_critter_stat(dude_obj, 35) > (get_critter_stat(dude_obj, 7) * 0.30000)) then begin
					GVar9 := GVar9 + message_str(SCRIPT_MORBID, 181);
				end
				else begin
					GVar9 := GVar9 + message_str(SCRIPT_MORBID, 182);
				end
			end
		end
	end
	GVar9 := GVar9 + message_str(SCRIPT_MORBID, random(183, 186));
	if (get_poison(dude_obj)) then begin
		GVar9 := GVar9 + message_str(SCRIPT_MORBID, random(187, 190));
	end
	LVar0 := get_critter_stat(dude_obj, 37);
	if (LVar0 > 30) then begin
		if (LVar0 < 101) then begin
			GVar9 := GVar9 + message_str(SCRIPT_MORBID, 191);
		end
		else begin
			if (LVar0 < 201) then begin
				GVar9 := GVar9 + message_str(SCRIPT_MORBID, 192);
			end
			else begin
				if (LVar0 < 401) then begin
					GVar9 := GVar9 + message_str(SCRIPT_MORBID, 193);
				end
				else begin
					GVar9 := GVar9 + message_str(SCRIPT_MORBID, 194);
				end
			end
		end
	end
	if ((LVar0 > 30) and (LVar0 < 251)) then begin
		GVar9 := GVar9 + message_str(SCRIPT_MORBID, 195);
	end
	GVar6 := get_critter_stat(dude_obj, 7) - get_critter_stat(dude_obj, 35);
	if (local_var(1) >= 2) then begin
		GVar7 := 20 * GVar6;
		if (get_poison(dude_obj)) then begin
			GVar7 := GVar7 + 50;
		end
	end
	else begin
		GVar7 := 25 * GVar6;
		if (get_poison(dude_obj)) then begin
			GVar7 := GVar7 + 75;
		end
	end
	if ((game_time_hour >= 1900) or (game_time_hour < 600)) then begin
		GVar7 := GVar7 * (3 / 2);
	end
	gsay_message(SCRIPT_MORBID, GVar9, NEUTRAL_REACTION);
	call Morbid09a;
end

procedure Morbid09a
begin
	gsay_reply(SCRIPT_MORBID, message_str(SCRIPT_MORBID, 123) + GVar7 + message_str(SCRIPT_MORBID, 124));
	giq_option(4, SCRIPT_MORBID, 125, Morbid12, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_MORBID, 126, Morbid10, BAD_REACTION);
	giq_option(4, SCRIPT_MORBID, 127, Morbid11, NEUTRAL_REACTION);
	giq_option(-3, SCRIPT_MORBID, 128, Morbid12, NEUTRAL_REACTION);
	giq_option(-3, SCRIPT_MORBID, 129, Morbid11, NEUTRAL_REACTION);
end

procedure Morbid10
begin
	call Down_React;
	gsay_message(SCRIPT_MORBID, 130, BAD_REACTION);
end

procedure Morbid11
begin
	gsay_message(SCRIPT_MORBID, 131, NEUTRAL_REACTION);
end

procedure Morbid12
begin
	if (item_caps_total(dude_obj) < GVar7) then begin
		call Morbid08;
	end
	else begin
		item_caps_adjust(dude_obj, -GVar7);
		call Up_React;
		gsay_message(SCRIPT_MORBID, 132, NEUTRAL_REACTION);
		gfade_out(600);
		GVar10 := 300 * GVar6;
		if (get_poison(dude_obj)) then begin
			GVar10 := GVar10 + 1200;
		end
		critter_heal(dude_obj, get_critter_stat(dude_obj, 7) - get_critter_stat(dude_obj, 35));
		poison(dude_obj, -get_poison(dude_obj));
		game_time_advance(game_ticks(GVar10));
		gfade_in(600);
		gsay_message(SCRIPT_MORBID, 133, NEUTRAL_REACTION);
	end
end

procedure Morbid13
begin
	gsay_reply(SCRIPT_MORBID, 134);
	giq_option(4, SCRIPT_MORBID, 135, Morbid03, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_MORBID, 136, Morbid14, NEUTRAL_REACTION);
	giq_option(-3, SCRIPT_MORBID, 137, Morbid03, NEUTRAL_REACTION);
	if ((global_var(GVAR_DESTROY_MASTER_1) == 1) and (local_var(8) == 0)) then begin
		giq_option(4, SCRIPT_MORBID, 233, Morbid27, BAD_REACTION);
	end
end

procedure Morbid14
begin
	gsay_message(SCRIPT_MORBID, 138, NEUTRAL_REACTION);
end

procedure Morbid15
begin
	gsay_reply(SCRIPT_MORBID, 139);
	giq_option(4, SCRIPT_MORBID, 140, Morbid03, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_MORBID, 141, Morbid03, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_MORBID, 142, Morbid02, NEUTRAL_REACTION);
	giq_option(-3, SCRIPT_MORBID, 143, Morbid03, NEUTRAL_REACTION);
end

procedure Morbid16
begin
	gsay_reply(SCRIPT_MORBID, 144);
	giq_option(4, SCRIPT_MORBID, 145, Morbid03, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_MORBID, 146, Morbid14, NEUTRAL_REACTION);
	giq_option(-3, SCRIPT_MORBID, 147, Morbid03, NEUTRAL_REACTION);
end

procedure Morbid17
begin
	set_local_var(7, 1);
	if (local_var(1) < 2) then begin
		call Up_React_Level;
	end
	gsay_reply(SCRIPT_MORBID, 148);
	giq_option(4, SCRIPT_MORBID, 149, Morbid03, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_MORBID, 150, Morbid19, NEUTRAL_REACTION);
	giq_option(5, SCRIPT_MORBID, 151, Morbid18, NEUTRAL_REACTION);
	giq_option(-3, SCRIPT_MORBID, 152, Morbid03, NEUTRAL_REACTION);
	if ((global_var(GVAR_DESTROY_MASTER_1) == 1) and (local_var(8) == 0)) then begin
		giq_option(4, SCRIPT_MORBID, 233, Morbid27, BAD_REACTION);
	end
end

procedure Morbid18
begin
	gsay_reply(SCRIPT_MORBID, 153);
	giq_option(5, SCRIPT_MORBID, 154, Morbid03, NEUTRAL_REACTION);
	giq_option(5, SCRIPT_MORBID, 155, Morbid20, NEUTRAL_REACTION);
	giq_option(5, SCRIPT_MORBID, 156, Morbid19, NEUTRAL_REACTION);
end

procedure Morbid19
begin
	gsay_message(SCRIPT_MORBID, 157, NEUTRAL_REACTION);
end

procedure Morbid20
begin
	variable LVar0 := 0;
	LVar0 := message_str(SCRIPT_MORBID, 158);
	if (not(global_var(GVAR_KILLIAN_DEAD))) then begin
		LVar0 := LVar0 + message_str(SCRIPT_MORBID, 159);
	end
	LVar0 := LVar0 + message_str(SCRIPT_MORBID, 160);
	gsay_reply(SCRIPT_MORBID, LVar0);
	giq_option(4, SCRIPT_MORBID, 161, Morbid03, NEUTRAL_REACTION);
	giq_option(5, SCRIPT_MORBID, 162, Morbid19, NEUTRAL_REACTION);
end

procedure Morbid21
begin
	gsay_reply(SCRIPT_MORBID, 163);
	giq_option(4, SCRIPT_MORBID, 164, Morbid03, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_MORBID, 165, Morbid03, NEUTRAL_REACTION);
	giq_option(-3, SCRIPT_MORBID, 166, Morbid03, NEUTRAL_REACTION);
	if ((global_var(GVAR_DESTROY_MASTER_1) == 1) and (local_var(8) == 0)) then begin
		giq_option(4, SCRIPT_MORBID, 233, Morbid27, BAD_REACTION);
	end
end

procedure Morbid22
begin
	gsay_reply(SCRIPT_MORBID, 167);
	giq_option(4, SCRIPT_MORBID, 168, Morbid03, NEUTRAL_REACTION);
	giq_option(5, SCRIPT_MORBID, 169, Morbid03, NEUTRAL_REACTION);
	giq_option(-3, SCRIPT_MORBID, 170, Morbid03, NEUTRAL_REACTION);
end

procedure Morbid23
begin
	gsay_message(SCRIPT_MORBID, 171, NEUTRAL_REACTION);
end

procedure Morbid24
begin
	gsay_message(SCRIPT_MORBID, 172, NEUTRAL_REACTION);
end

procedure Morbid25
begin
	gsay_message(SCRIPT_MORBID, 173, NEUTRAL_REACTION);
end

procedure Morbid26
begin
	gsay_reply(SCRIPT_MORBID, 174);
	giq_option(4, SCRIPT_MORBID, 175, Morbid03, NEUTRAL_REACTION);
	giq_option(5, SCRIPT_MORBID, 176, Morbid03, NEUTRAL_REACTION);
	giq_option(-3, SCRIPT_MORBID, 177, Morbid03, NEUTRAL_REACTION);
end

procedure Morbid27
begin
	set_local_var(8, 1);
	gsay_reply(SCRIPT_MORBID, 234);
	giq_option(4, SCRIPT_MORBID, 235, Morbid28, BAD_REACTION);
end

procedure Morbid28
begin
	call Bottom_React;
	gsay_message(SCRIPT_MORBID, 236, BAD_REACTION);
end

procedure Morbid00L
begin
	gsay_reply(SCRIPT_MORBID, 204);
	set_local_var(5, 1);
	giq_option(4, SCRIPT_MORBID, 207, MorbidCombat, BAD_REACTION);
	giq_option(6, SCRIPT_MORBID, 208, Morbid00La, NEUTRAL_REACTION);
	giq_option(-3, SCRIPT_MORBID, 209, MorbidCombat, NEUTRAL_REACTION);
end

procedure Morbid00La
begin
	if (is_success(roll_vs_skill(dude_obj, 14, 0))) then begin
		call Morbid02L;
	end
	else begin
		call Morbid01L;
	end
end

procedure Morbid01L
begin
	gsay_message(SCRIPT_MORBID, 210, BAD_REACTION);
	Gretch_call := 1;
end

procedure Morbid02L
begin
	gsay_reply(SCRIPT_MORBID, 211);
	giq_option(5, SCRIPT_MORBID, 212, Morbid02La, NEUTRAL_REACTION);
	if (global_var(GVAR_DESTROY_MASTER_1) == 1) then begin
		giq_option(5, SCRIPT_MORBID, 213, Morbid03L, BAD_REACTION);
	end
end

procedure Morbid02La
begin
	if (is_success(roll_vs_skill(dude_obj, 14, 0))) then begin
		call Morbid04L;
	end
	else begin
		call Morbid01L;
	end
end

procedure Morbid03L
begin
	gsay_message(SCRIPT_MORBID, 214, BAD_REACTION);
	Gretch_call := 1;
end

procedure Morbid04L
begin
	gsay_reply(SCRIPT_MORBID, 215);
	giq_option(5, SCRIPT_MORBID, 216, Morbid06L, NEUTRAL_REACTION);
	giq_option(5, SCRIPT_MORBID, 217, Morbid05L, NEUTRAL_REACTION);
end

procedure Morbid05L
begin
	variable LVar0 := 0;
	LVar0 := message_str(SCRIPT_MORBID, 218);
	LVar0 := LVar0 + message_str(SCRIPT_MORBID, 220);
	gsay_reply(SCRIPT_MORBID, LVar0);
	giq_option(5, SCRIPT_MORBID, 221, Morbid07L, NEUTRAL_REACTION);
	giq_option(5, SCRIPT_MORBID, 222, Morbid06L, NEUTRAL_REACTION);
end

procedure Morbid06L
begin
	gsay_message(SCRIPT_MORBID, 223, BAD_REACTION);
	Gretch_call := 1;
end

procedure Morbid07L
begin
	gsay_reply(SCRIPT_MORBID, 224);
	giq_option(5, SCRIPT_MORBID, 225, Morbid08L, NEUTRAL_REACTION);
	giq_option(5, SCRIPT_MORBID, 226, Morbid06L, NEUTRAL_REACTION);
end

procedure Morbid08L
begin
	gsay_message(SCRIPT_MORBID, 227, NEUTRAL_REACTION);
	GVar11 := 1;
end

procedure Morbid09L
begin
	GVar12 := 0;
	gsay_reply(SCRIPT_MORBID, 229);
	giq_option(5, SCRIPT_MORBID, 230, Morbid10L, NEUTRAL_REACTION);
end

procedure Morbid10L
begin
	gsay_message(SCRIPT_MORBID, 231, NEUTRAL_REACTION);
end

procedure Morbid00N
begin
	gsay_reply(SCRIPT_MORBID, 196);
	giq_option(4, SCRIPT_MORBID, 197, Morbid00Na, NEUTRAL_REACTION);
	giq_option(5, SCRIPT_MORBID, 198, Morbid00Nb, NEUTRAL_REACTION);
	giq_option(-3, SCRIPT_MORBID, 199, Morbid03N, NEUTRAL_REACTION);
end

procedure Morbid00Na
begin
	if (get_critter_stat(dude_obj, 35) < (get_critter_stat(dude_obj, 7) - 7)) then begin
		call Morbid03;
	end
	else begin
		call Morbid01;
	end
end

procedure Morbid00Nb
begin
	if (get_critter_stat(dude_obj, 35) < (get_critter_stat(dude_obj, 7) - 3)) then begin
		call Morbid03;
	end
	else begin
		call Morbid02N;
	end
end

procedure Morbid01N
begin
	call Down_React;
	gsay_message(SCRIPT_MORBID, 200, BAD_REACTION);
end

procedure Morbid02N
begin
	gsay_message(SCRIPT_MORBID, 201, NEUTRAL_REACTION);
end

procedure Morbid03N
begin
	gsay_message(SCRIPT_MORBID, 202, NEUTRAL_REACTION);
end

procedure Morbid04N
begin
	gsay_reply(SCRIPT_MORBID, 203);
	giq_option(4, SCRIPT_MORBID, 197, Morbid00Na, NEUTRAL_REACTION);
	giq_option(5, SCRIPT_MORBID, 198, Morbid00Nb, NEUTRAL_REACTION);
	giq_option(-3, SCRIPT_MORBID, 199, Morbid03N, NEUTRAL_REACTION);
end

procedure get_eye
begin
	game_ui_disable;
	GVar11 := 0;
	reg_anim_func(2, dude_obj);
	reg_anim_func(2, self_obj);
	reg_anim_func(1, 1);
	reg_anim_obj_move_to_obj(self_obj, dude_obj, -1);
	reg_anim_animate(self_obj, 12, -1);
	reg_anim_func(3, 0);
	rm_timer_event(self_obj);
	add_timer_event(self_obj, game_ticks(3), 1);
	display_msg(message_str(SCRIPT_MORBID, 228));
end

procedure MorbidCombat
begin
	GVar5 := 1;
end

procedure MorbidEnd
begin
end

procedure sleeping
begin
	if (local_var(6) == 1) then begin
		if (not(GVar0) and (game_time_hour >= GVar1) and (game_time_hour < GVar2) or (GVar0 and ((game_time_hour >= GVar1) or (game_time_hour < GVar2)))) then begin
			if (((game_time_hour - GVar1) < 10) and ((game_time_hour - GVar1) > 0)) then begin
				if (tile_num(self_obj) != GVar3) then begin
					animate_move_obj_to_tile(self_obj, GVar3, ANIMATE_WALK);
				end
				else begin
					set_local_var(6, 0);
				end
			end
			else begin
				move_to(self_obj, GVar3, elevation(self_obj));
				if (tile_num(self_obj) == GVar3) then begin
					set_local_var(6, 0);
				end
			end
		end
	end
	else begin
		if (GVar0 and (game_time_hour >= GVar2) and (game_time_hour < GVar1) or (not(GVar0) and ((game_time_hour >= GVar2) or (game_time_hour < GVar1)))) then begin
			if (((game_time_hour - GVar2) < 10) and ((game_time_hour - GVar2) > 0)) then begin
				if (tile_num(self_obj) != GVar4) then begin
					animate_move_obj_to_tile(self_obj, self_obj, ANIMATE_WALK);
				end
				else begin
					set_local_var(6, 1);
				end
			end
			else begin
				if (tile_num(self_obj) != GVar4) then begin
					move_to(self_obj, GVar4, elevation(self_obj));
				end
				else begin
					set_local_var(6, 1);
				end
			end
		end
	end
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
	GVar14 := message_str(SCRIPT_MODREACT, random(100, 105));
end

procedure combat_p_proc
begin
	if (fixed_param == 4) then begin
		set_local_var(9, 1);
		if (elevation(self_obj) == 0) then begin
			script_overrides;
			use_obj(ladder_down);
		end
	end
end

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