#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 talk_p_proc;
procedure ChdGuard0;
procedure ChdGuard1;
procedure ChdGuard2;
procedure ChdGuard3;
procedure ChdGuard4;
procedure ChdGuard5;
procedure ChdGuard6;
procedure ChdGuard7;
procedure ChdGuard8;
procedure ChdGuard9;
procedure ChdGuard10;
procedure ChdGuard11;
procedure ChdGuard12;
procedure ChdGuard13;
procedure ChdGuard14;
procedure ChdGuard15;
procedure ChdGuard16;
procedure ChdGuard17;
procedure ChdGuard17a;
procedure ChdGuard18;
procedure ChdGuard19;
procedure ChdGuard20;
procedure ChdGuard21;
procedure ChdGuard22;
procedure ChdGuard23;
procedure ChdGuard24;
procedure ChdGuard25;
procedure ChdGuard26;
procedure ChdGuard27;
procedure ChdGuard28;
procedure ChdGuard29;
procedure ChdGuard30;
procedure ChdGuard31;
procedure ChdGuard32;
procedure ChdGuard33;
procedure ChdGuard34;
procedure ChdGuard35;
procedure ChdGuardend;
procedure combat;

variable hostile1;
variable initialized1;


procedure start
begin
	if (not(initialized1)) then begin
		critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_TEAM_NUM, 20);
		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 == talk_proc) then begin
						call talk_p_proc;
					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_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

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

procedure talk_p_proc
begin
	script_overrides;
	if (local_var(0)) then begin
		call ChdGuard35;
	end
	else begin
		set_local_var(0, 1);
		start_gdialog(SCRIPT_CHDGUARD, self_obj, 4, -1, -1);
		gsay_start;
		call ChdGuard0;
		gsay_end;
		end_dialogue;
	end
end

procedure ChdGuard0
begin
	gsay_reply(SCRIPT_CHDGUARD, 101);
	giq_option(-3, SCRIPT_CHDGUARD, 102, ChdGuard1, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_CHDGUARD, 103, ChdGuard13, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_CHDGUARD, 104, ChdGuard25, NEUTRAL_REACTION);
	giq_option(6, SCRIPT_CHDGUARD, 105, ChdGuard26, NEUTRAL_REACTION);
	giq_option(6, SCRIPT_CHDGUARD, 106, ChdGuard27, NEUTRAL_REACTION);
end

procedure ChdGuard1
begin
	gsay_reply(SCRIPT_CHDGUARD, 107);
	giq_option(-3, SCRIPT_CHDGUARD, 108, ChdGuard2, NEUTRAL_REACTION);
	giq_option(-3, SCRIPT_CHDGUARD, 109, combat, NEUTRAL_REACTION);
	giq_option(-3, SCRIPT_CHDGUARD, 110, ChdGuard9, NEUTRAL_REACTION);
end

procedure ChdGuard2
begin
	gsay_reply(SCRIPT_CHDGUARD, 111);
	giq_option(-3, SCRIPT_CHDGUARD, 112, combat, NEUTRAL_REACTION);
	giq_option(-3, SCRIPT_CHDGUARD, 113, ChdGuard3, NEUTRAL_REACTION);
	giq_option(-3, SCRIPT_CHDGUARD, 114, ChdGuard4, NEUTRAL_REACTION);
end

procedure ChdGuard3
begin
	gsay_message(SCRIPT_CHDGUARD, 115, NEUTRAL_REACTION);
end

procedure ChdGuard4
begin
	gsay_reply(SCRIPT_CHDGUARD, 116);
	giq_option(-3, SCRIPT_CHDGUARD, 117, ChdGuard5, NEUTRAL_REACTION);
	giq_option(-3, SCRIPT_CHDGUARD, 118, combat, NEUTRAL_REACTION);
	giq_option(-3, SCRIPT_CHDGUARD, 119, ChdGuard6, NEUTRAL_REACTION);
end

procedure ChdGuard5
begin
	gsay_message(SCRIPT_CHDGUARD, 120, NEUTRAL_REACTION);
end

procedure ChdGuard6
begin
	gsay_reply(SCRIPT_CHDGUARD, 121);
	giq_option(-3, SCRIPT_CHDGUARD, 122, ChdGuard7, NEUTRAL_REACTION);
	giq_option(-3, SCRIPT_CHDGUARD, 123, ChdGuard5, NEUTRAL_REACTION);
	giq_option(-3, SCRIPT_CHDGUARD, 124, ChdGuard8, NEUTRAL_REACTION);
end

procedure ChdGuard7
begin
	gsay_message(SCRIPT_CHDGUARD, 125, NEUTRAL_REACTION);
end

procedure ChdGuard8
begin
	gsay_message(SCRIPT_CHDGUARD, 126, NEUTRAL_REACTION);
end

procedure ChdGuard9
begin
	gsay_reply(SCRIPT_CHDGUARD, 127);
	giq_option(-3, SCRIPT_CHDGUARD, 128, ChdGuard10, NEUTRAL_REACTION);
	giq_option(-3, SCRIPT_CHDGUARD, 129, ChdGuard12, NEUTRAL_REACTION);
	giq_option(-3, SCRIPT_CHDGUARD, 130, ChdGuardend, NEUTRAL_REACTION);
end

procedure ChdGuard10
begin
	gsay_reply(SCRIPT_CHDGUARD, 131);
	giq_option(-3, SCRIPT_CHDGUARD, 132, ChdGuard11, NEUTRAL_REACTION);
	giq_option(-3, SCRIPT_CHDGUARD, 133, ChdGuardend, NEUTRAL_REACTION);
end

procedure ChdGuard11
begin
	gsay_message(SCRIPT_CHDGUARD, 134, NEUTRAL_REACTION);
end

procedure ChdGuard12
begin
	gsay_reply(SCRIPT_CHDGUARD, 135);
	giq_option(-3, SCRIPT_CHDGUARD, 136, ChdGuardend, NEUTRAL_REACTION);
end

procedure ChdGuard13
begin
	gsay_reply(SCRIPT_CHDGUARD, 137);
	giq_option(4, SCRIPT_CHDGUARD, 138, ChdGuard14, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_CHDGUARD, 139, ChdGuard15, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_CHDGUARD, message_str(SCRIPT_CHDGUARD, 140) + proto_data(obj_pid(dude_obj), 1) + message_str(SCRIPT_CHDGUARD, 141), ChdGuard22, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_CHDGUARD, 142, ChdGuard24, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_CHDGUARD, 143, combat, NEUTRAL_REACTION);
end

procedure ChdGuard14
begin
	gsay_message(SCRIPT_CHDGUARD, 144, NEUTRAL_REACTION);
	call combat;
end

procedure ChdGuard15
begin
	gsay_reply(SCRIPT_CHDGUARD, 145);
	giq_option(4, SCRIPT_CHDGUARD, 146, ChdGuard16, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_CHDGUARD, 147, ChdGuard17, NEUTRAL_REACTION);
end

procedure ChdGuard16
begin
	gsay_message(SCRIPT_CHDGUARD, 148, NEUTRAL_REACTION);
	call combat;
end

procedure ChdGuard17
begin
	gsay_reply(SCRIPT_CHDGUARD, 149);
	giq_option(4, SCRIPT_CHDGUARD, message_str(SCRIPT_CHDGUARD, 150) + proto_data(obj_pid(dude_obj), 1) + message_str(SCRIPT_CHDGUARD, 151), ChdGuard17a, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_CHDGUARD, 152, ChdGuard20, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_CHDGUARD, 153, combat, NEUTRAL_REACTION);
end

procedure ChdGuard17a
begin
	if (is_success(roll_vs_skill(dude_obj, 14, 0))) then begin
		call ChdGuard18;
	end
	else begin
		call ChdGuard19;
	end
end

procedure ChdGuard18
begin
	gsay_message(SCRIPT_CHDGUARD, 154, NEUTRAL_REACTION);
end

procedure ChdGuard19
begin
	gsay_message(SCRIPT_CHDGUARD, 155, NEUTRAL_REACTION);
	call combat;
end

procedure ChdGuard20
begin
	gsay_reply(SCRIPT_CHDGUARD, 156);
	giq_option(4, SCRIPT_CHDGUARD, message_str(SCRIPT_CHDGUARD, 157) + proto_data(obj_pid(dude_obj), 1) + message_str(SCRIPT_CHDGUARD, 158), ChdGuard21, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_CHDGUARD, 159, combat, NEUTRAL_REACTION);
end

procedure ChdGuard21
begin
	gsay_message(SCRIPT_CHDGUARD, 160, NEUTRAL_REACTION);
	call ChdGuard17a;
end

procedure ChdGuard22
begin
	gsay_reply(SCRIPT_CHDGUARD, message_str(SCRIPT_CHDGUARD, 161) + proto_data(obj_pid(dude_obj), 1) + message_str(SCRIPT_CHDGUARD, 162));
	giq_option(4, SCRIPT_CHDGUARD, 163, ChdGuard23, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_CHDGUARD, 164, ChdGuard23, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_CHDGUARD, 165, combat, NEUTRAL_REACTION);
end

procedure ChdGuard23
begin
	gsay_message(SCRIPT_CHDGUARD, 166, NEUTRAL_REACTION);
	call combat;
end

procedure ChdGuard24
begin
	gsay_message(SCRIPT_CHDGUARD, 167, NEUTRAL_REACTION);
	call combat;
end

procedure ChdGuard25
begin
	gsay_reply(SCRIPT_CHDGUARD, 168);
	giq_option(4, SCRIPT_CHDGUARD, 169, ChdGuard14, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_CHDGUARD, 170, ChdGuard15, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_CHDGUARD, message_str(SCRIPT_CHDGUARD, 171) + proto_data(obj_pid(dude_obj), 1) + message_str(SCRIPT_CHDGUARD, 172), ChdGuard22, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_CHDGUARD, 173, ChdGuard24, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_CHDGUARD, 174, combat, NEUTRAL_REACTION);
end

procedure ChdGuard26
begin
	gsay_message(SCRIPT_CHDGUARD, 175, NEUTRAL_REACTION);
	call combat;
end

procedure ChdGuard27
begin
	gsay_reply(SCRIPT_CHDGUARD, 176);
	giq_option(6, SCRIPT_CHDGUARD, 177, ChdGuard28, NEUTRAL_REACTION);
	giq_option(6, SCRIPT_CHDGUARD, 178, ChdGuard29, NEUTRAL_REACTION);
	giq_option(6, SCRIPT_CHDGUARD, 179, ChdGuard30, NEUTRAL_REACTION);
	giq_option(6, SCRIPT_CHDGUARD, 180, ChdGuard34, NEUTRAL_REACTION);
end

procedure ChdGuard28
begin
	gsay_message(SCRIPT_CHDGUARD, 181, NEUTRAL_REACTION);
end

procedure ChdGuard29
begin
	gsay_message(SCRIPT_CHDGUARD, 182, NEUTRAL_REACTION);
end

procedure ChdGuard30
begin
	gsay_reply(SCRIPT_CHDGUARD, 183);
	giq_option(6, SCRIPT_CHDGUARD, 184, ChdGuard31, NEUTRAL_REACTION);
	giq_option(6, SCRIPT_CHDGUARD, 185, ChdGuard32, NEUTRAL_REACTION);
	giq_option(6, SCRIPT_CHDGUARD, 186, combat, NEUTRAL_REACTION);
end

procedure ChdGuard31
begin
	gsay_message(SCRIPT_CHDGUARD, 187, NEUTRAL_REACTION);
	call combat;
end

procedure ChdGuard32
begin
	gsay_reply(SCRIPT_CHDGUARD, 188);
	giq_option(6, SCRIPT_CHDGUARD, 189, ChdGuard33, NEUTRAL_REACTION);
	giq_option(6, SCRIPT_CHDGUARD, 190, ChdGuard33, NEUTRAL_REACTION);
	giq_option(6, SCRIPT_CHDGUARD, 191, combat, NEUTRAL_REACTION);
end

procedure ChdGuard33
begin
	gsay_reply(SCRIPT_CHDGUARD, 192);
	giq_option(6, SCRIPT_CHDGUARD, 193, ChdGuardend, NEUTRAL_REACTION);
	giq_option(6, SCRIPT_CHDGUARD, 194, combat, NEUTRAL_REACTION);
end

procedure ChdGuard34
begin
	gsay_message(SCRIPT_CHDGUARD, 195, NEUTRAL_REACTION);
	call combat;
end

procedure ChdGuard35
begin
	gsay_message(SCRIPT_CHDGUARD, 196, NEUTRAL_REACTION);
	call combat;
end

procedure ChdGuardend
begin
end

procedure combat
begin
	hostile1 := 1;
end