#include <define.h>

//#define NAME                    SCRIPT_

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



procedure start;
#include <push.h>
procedure do_dialogue;
procedure social_skills;
procedure DocWu00;
procedure DocWu01;
procedure DocWu02;
procedure DocWu03;
procedure DocWu04;
procedure DocWu05;
procedure DocWu06;
procedure DocWu06a;
procedure DocWu07;
procedure DocWu08;
procedure DocWu09;
procedure DocWu10;
procedure DocWu10a;
procedure DocWu10b;
procedure DocWu10c;
procedure DocWu11;
procedure DocWu12;
procedure DocWu13;
procedure DocWu14;
procedure DocWu15;
procedure DocWu16;
procedure DocWu17;
procedure DocWu17a;
procedure DocWu17b;
procedure DocWu18;
procedure DocWu19;
procedure DocWu19a;
procedure DocWu19b;
procedure DocWu20;
procedure DocWu20a;
procedure DocWu20b;
procedure DocWu21;
procedure DocWu21a;
procedure DocWu22;
procedure DocWu23;
procedure DocWu24;
procedure DocWu24a;
procedure DocWu24b;
procedure DocWuOpts1;
procedure DocWuOpts2;
procedure DocWuOpts3;
procedure DocWuOpts4;
procedure DocWuOpts5;
procedure DocWuOpts5a;
procedure DocWuEnd;

variable healing;
variable Only_Once := 1;
variable hostile1;

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
		critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_TEAM_NUM, 20);
		critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_AI_PACKET, AI_CHILDREN_TRUE);
		Only_Once := 0;
	end
	if (script_action == talk_proc) then begin
		call do_dialogue;
	end
	else begin
		if (script_action == destroy_proc) then 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
		end
		else begin
			if (script_action == critter_proc) then begin
				if (hostile1) then begin
					hostile1 := 0;
					attack_complex(dude_obj, 0, 1, 0, 0, 30000, 0, 0);
				end
			end
			else begin
				if ((script_action == look_at_proc) or (script_action == description_proc)) then begin
				end
				else begin
					if (script_action == pickup_proc) then begin
						hostile1 := 1;
					end
					else begin
						if (script_action == timed_event_proc) then begin
							if (fixed_param == 1) then begin
								if ((healing == 1) or (healing == 3)) then begin
									float_msg(dude_obj, message_str(SCRIPT_DOCWU, 138), FLOAT_MSG_RED);
								end
								else begin
									if (healing == 2) then begin
										float_msg(dude_obj, message_str(SCRIPT_DOCWU, 152), FLOAT_MSG_RED);
									end
									else begin
										if (healing == 4) then begin
											float_msg(dude_obj, message_str(SCRIPT_DOCWU, 175), FLOAT_MSG_RED);
										end
										else begin
											if (healing == 5) then begin
												float_msg(self_obj, message_str(SCRIPT_DOCWU, 150), FLOAT_MSG_YELLOW);
											end
											else begin
												if (healing == 6) then begin
													float_msg(self_obj, message_str(SCRIPT_DOCWU, 178), FLOAT_MSG_YELLOW);
												end
											end
										end
									end
								end
								add_timer_event(self_obj, game_ticks(3), 2);
							end
							else begin
								if (fixed_param == 2) then begin
									if (healing < 4) then begin
										float_msg(self_obj, message_str(SCRIPT_DOCWU, 139), FLOAT_MSG_YELLOW);
									end
									else begin
										if (healing == 4) then begin
											float_msg(self_obj, message_str(SCRIPT_DOCWU, 176), FLOAT_MSG_YELLOW);
										end
									end
									add_timer_event(self_obj, game_ticks(3), 3);
								end
								else begin
									if (fixed_param == 3) then begin
										if (healing == 1) then begin
											if (dude_is_male) then begin
												float_msg(self_obj, message_str(SCRIPT_DOCWU, 140), FLOAT_MSG_YELLOW);
											end
											else begin
												float_msg(self_obj, message_str(SCRIPT_DOCWU, 141), FLOAT_MSG_YELLOW);
											end
										end
										else begin
											if (healing == 2) then begin
												float_msg(self_obj, message_str(SCRIPT_DOCWU, 153), FLOAT_MSG_YELLOW);
											end
											else begin
												if (healing == 3) then begin
													if (dude_is_male) then begin
														float_msg(self_obj, message_str(SCRIPT_DOCWU, 167), FLOAT_MSG_YELLOW);
													end
													else begin
														float_msg(self_obj, message_str(SCRIPT_DOCWU, 168), FLOAT_MSG_YELLOW);
													end
												end
											end
										end
									end
								end
							end
						end
					end
				end
			end
		end
	end
end

procedure do_dialogue
begin
	call Get_Reaction;
	start_gdialog(SCRIPT_DOCWU, self_obj, 4, -1, -1);
	gsay_start;
	healing := 0;
	if (local_var(5) == 1) then begin
		call DocWu00;
	end
	else begin
		if (local_var(6) == 1) then begin
			call DocWu01;
		end
		else begin
			if (local_var(7) == 1) then begin
				call DocWu02;
			end
			else begin
				call DocWu03;
			end
		end
	end
	gsay_end;
	end_dialogue;
	if (healing) then begin
		use_obj(dude_obj);
		add_timer_event(self_obj, game_ticks(2), 1);
	end
end

procedure social_skills
begin
	call Get_Reaction;
	dialogue_system_enter;
end

procedure DocWu00
begin
	variable LVar0 := 0;
	set_local_var(4, 1);
	set_local_var(5, 1);
	if (dude_is_male) then begin
		gsay_reply(SCRIPT_DOCWU, message_str(SCRIPT_DOCWU, 102));
	end
	else begin
		gsay_reply(SCRIPT_DOCWU, message_str(SCRIPT_DOCWU, 103));
	end
	giq_option(7, SCRIPT_DOCWU, 106, DocWu04, NEUTRAL_REACTION);
	call DocWuOpts1;
	giq_option(4, SCRIPT_DOCWU, 109, DocWu07, NEUTRAL_REACTION);
	call DocWuOpts2;
	giq_option(4, SCRIPT_DOCWU, 111, DocWu09, NEUTRAL_REACTION);
	call DocWuOpts3;
end

procedure DocWu01
begin
	set_local_var(6, 1);
	gsay_reply(SCRIPT_DOCWU, 113);
	giq_option(7, SCRIPT_DOCWU, 114, DocWu11, NEUTRAL_REACTION);
	call DocWuOpts1;
	giq_option(4, SCRIPT_DOCWU, 115, DocWu12, NEUTRAL_REACTION);
	call DocWuOpts2;
	giq_option(4, SCRIPT_DOCWU, 116, DocWu09, NEUTRAL_REACTION);
	call DocWuOpts3;
end

procedure DocWu02
begin
	set_local_var(7, 1);
	gsay_reply(SCRIPT_DOCWU, 117);
	giq_option(7, SCRIPT_DOCWU, 118, DocWu13, NEUTRAL_REACTION);
	call DocWuOpts1;
	giq_option(4, SCRIPT_DOCWU, 119, DocWu12, NEUTRAL_REACTION);
	call DocWuOpts2;
	giq_option(4, SCRIPT_DOCWU, 120, DocWu14, NEUTRAL_REACTION);
	call DocWuOpts3;
end

procedure DocWu03
begin
	set_local_var(5, 0);
	set_local_var(6, 0);
	set_local_var(7, 0);
	gsay_reply(SCRIPT_DOCWU, 121);
	giq_option(7, SCRIPT_DOCWU, 122, DocWu15, NEUTRAL_REACTION);
	call DocWuOpts1;
	giq_option(4, SCRIPT_DOCWU, 123, DocWu12, NEUTRAL_REACTION);
	call DocWuOpts2;
	giq_option(4, SCRIPT_DOCWU, 124, DocWu14, NEUTRAL_REACTION);
	call DocWuOpts3;
end

procedure DocWu04
begin
	gsay_reply(SCRIPT_DOCWU, 125);
	giq_option(7, SCRIPT_DOCWU, 126, DocWu16, NEUTRAL_REACTION);
	call DocWuOpts4;
end

procedure DocWu05
begin
	gsay_reply(SCRIPT_DOCWU, 130);
	giq_option(0, SCRIPT_DOCWU, 101, DocWuEnd, NEUTRAL_REACTION);
end

procedure DocWu06
begin
	gsay_reply(SCRIPT_DOCWU, 131);
	giq_option(0, SCRIPT_DOCWU, 100, DocWu06a, NEUTRAL_REACTION);
end

procedure DocWu06a
begin
	healing := 1;
end

procedure DocWu07
begin
	gsay_reply(SCRIPT_DOCWU, 142);
	call DocWuOpts4;
end

procedure DocWu08
begin
	gsay_reply(SCRIPT_DOCWU, 143);
	giq_option(0, SCRIPT_DOCWU, 101, DocWuEnd, NEUTRAL_REACTION);
end

procedure DocWu09
begin
	gsay_reply(SCRIPT_DOCWU, 144);
	giq_option(4, SCRIPT_DOCWU, 145, DocWu06, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DOCWU, 146, DocWu23, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DOCWU, 147, DocWu24, NEUTRAL_REACTION);
end

procedure DocWu10
begin
	gsay_reply(SCRIPT_DOCWU, 148);
	giq_option(0, SCRIPT_DOCWU, 100, DocWu10a, NEUTRAL_REACTION);
end

procedure DocWu10a
begin
	gsay_reply(SCRIPT_DOCWU, 151);
	giq_option(0, SCRIPT_DOCWU, 100, DocWu10c, NEUTRAL_REACTION);
end

procedure DocWu10b
begin
	healing := 5;
end

procedure DocWu10c
begin
	healing := 2;
end

procedure DocWu11
begin
	gsay_reply(SCRIPT_DOCWU, 154);
	call DocWuOpts4;
end

procedure DocWu12
begin
	gsay_reply(SCRIPT_DOCWU, 155);
	call DocWuOpts4;
end

procedure DocWu13
begin
	gsay_reply(SCRIPT_DOCWU, 156);
	call DocWuOpts4;
end

procedure DocWu14
begin
	gsay_reply(SCRIPT_DOCWU, 157);
	giq_option(4, SCRIPT_DOCWU, 158, DocWu06, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DOCWU, 159, DocWu23, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DOCWU, 160, DocWu24, NEUTRAL_REACTION);
end

procedure DocWu15
begin
	gsay_reply(SCRIPT_DOCWU, 161);
	giq_option(4, SCRIPT_DOCWU, 162, DocWu06, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DOCWU, 163, DocWu23, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DOCWU, 160, DocWu24, NEUTRAL_REACTION);
end

procedure DocWu16
begin
	gsay_reply(SCRIPT_DOCWU, 164);
	giq_option(4, SCRIPT_DOCWU, 162, DocWu06, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DOCWU, 163, DocWu23, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DOCWU, 160, DocWu24, NEUTRAL_REACTION);
end

procedure DocWu17
begin
	gsay_reply(SCRIPT_DOCWU, 165);
	giq_option(0, SCRIPT_DOCWU, 100, DocWu17a, NEUTRAL_REACTION);
end

procedure DocWu17a
begin
	gsay_reply(SCRIPT_DOCWU, 166);
	giq_option(0, SCRIPT_DOCWU, 100, DocWu17b, NEUTRAL_REACTION);
end

procedure DocWu17b
begin
	healing := 3;
end

procedure DocWu18
begin
	gsay_reply(SCRIPT_DOCWU, 169);
	giq_option(0, SCRIPT_DOCWU, 101, DocWuEnd, NEUTRAL_REACTION);
end

procedure DocWu19
begin
	variable LVar0 := 0;
	variable LVar1 := 0;
	LVar1 := get_critter_stat(dude_obj, 7);
	LVar0 := get_critter_stat(dude_obj, 35);
	if (LVar0 == LVar1) then begin
		gsay_reply(SCRIPT_DOCWU, 170);
		giq_option(0, SCRIPT_DOCWU, 101, DocWuEnd, NEUTRAL_REACTION);
	end
	else begin
		if (LVar0 > (LVar1 / 2)) then begin
			call DocWu19a;
		end
		else begin
			call DocWu19b;
		end
	end
end

procedure DocWu19a
begin
	gsay_reply(SCRIPT_DOCWU, 171);
	giq_option(4, SCRIPT_DOCWU, 127, DocWu06, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DOCWU, 173, DocWu23, NEUTRAL_REACTION);
end

procedure DocWu19b
begin
	gsay_reply(SCRIPT_DOCWU, 171);
	giq_option(4, SCRIPT_DOCWU, 127, DocWu06, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DOCWU, 173, DocWu18, NEUTRAL_REACTION);
end

procedure DocWu20
begin
	gsay_reply(SCRIPT_DOCWU, 174);
	giq_option(0, SCRIPT_DOCWU, 100, DocWu20a, NEUTRAL_REACTION);
end

procedure DocWu20a
begin
	gsay_reply(SCRIPT_DOCWU, 137);
	giq_option(0, SCRIPT_DOCWU, 100, DocWu20b, NEUTRAL_REACTION);
end

procedure DocWu20b
begin
	healing := 4;
end

procedure DocWu21
begin
	gsay_reply(SCRIPT_DOCWU, 177);
	giq_option(0, SCRIPT_DOCWU, 100, DocWu21a, NEUTRAL_REACTION);
end

procedure DocWu21a
begin
	healing := 6;
end

procedure DocWu22
begin
	gsay_reply(SCRIPT_DOCWU, 179);
	giq_option(0, SCRIPT_DOCWU, 101, DocWuEnd, NEUTRAL_REACTION);
end

procedure DocWu23
begin
	gsay_reply(SCRIPT_DOCWU, 180);
	giq_option(0, SCRIPT_DOCWU, 101, DocWuEnd, NEUTRAL_REACTION);
end

procedure DocWu24
begin
	variable LVar0 := 0;
	variable LVar1 := 0;
	LVar1 := get_critter_stat(dude_obj, 7);
	LVar0 := get_critter_stat(dude_obj, 35);
	if (LVar0 == LVar1) then begin
		gsay_reply(SCRIPT_DOCWU, 170);
		giq_option(0, SCRIPT_DOCWU, 101, DocWuEnd, NEUTRAL_REACTION);
	end
	else begin
		if (LVar0 > (LVar1 / 2)) then begin
			call DocWu24a;
		end
		else begin
			call DocWu24b;
		end
	end
end

procedure DocWu24a
begin
	gsay_reply(SCRIPT_DOCWU, 181);
	giq_option(4, SCRIPT_DOCWU, 127, DocWu17, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DOCWU, 173, DocWu23, NEUTRAL_REACTION);
end

procedure DocWu24b
begin
	gsay_reply(SCRIPT_DOCWU, 182);
	giq_option(4, SCRIPT_DOCWU, 183, DocWu06, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DOCWU, 173, DocWu23, NEUTRAL_REACTION);
end

procedure DocWuOpts1
begin
	giq_option(4, SCRIPT_DOCWU, 107, DocWu05, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DOCWU, 108, DocWu06, NEUTRAL_REACTION);
end

procedure DocWuOpts2
begin
	giq_option(4, SCRIPT_DOCWU, 110, DocWu08, NEUTRAL_REACTION);
end

procedure DocWuOpts3
begin
	giq_option(-3, SCRIPT_DOCWU, 112, DocWu10, NEUTRAL_REACTION);
	giq_option(-3, SCRIPT_DOCWU, 184, DocWuEnd, NEUTRAL_REACTION);
end

procedure DocWuOpts4
begin
	giq_option(4, SCRIPT_DOCWU, 127, DocWu17, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DOCWU, 128, DocWu18, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DOCWU, 129, DocWu19, NEUTRAL_REACTION);
end

procedure DocWuOpts5
begin
	gsay_reply(SCRIPT_DOCWU, 132);
	giq_option(7, SCRIPT_DOCWU, 133, DocWuOpts5a, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DOCWU, 134, DocWu21, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DOCWU, 135, DocWu22, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_DOCWU, 136, DocWuOpts5a, NEUTRAL_REACTION);
end

procedure DocWuOpts5a
begin
	if (is_success(roll_vs_skill(dude_obj, 14, 0))) then begin
		call DocWu20;
	end
	else begin
		call DocWu21;
	end
end

procedure DocWuEnd
begin
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