#include <define.h>

//#define NAME                    SCRIPT_

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



procedure start;
#include <push.h>
procedure critter_p_proc;
procedure damage_p_proc;
procedure destroy_p_proc;
procedure look_at_p_proc;
procedure pickup_p_proc;
procedure talk_p_proc;
procedure Sammael01;
procedure Sammael02;
procedure Sammael03;
procedure Sammael04;
procedure Sammael05;
procedure Sammael06;
procedure Sammael07;
procedure Sammael08;
procedure Sammael09;
procedure Sammael10;
procedure Sammael11;
procedure Sammael12;
procedure Sammael13;
procedure Sammael14;
procedure Sammael15;

variable hostile1;
variable initialized1;


procedure start
begin
	if (not(initialized1)) then begin
		if ((global_var(GVAR_BLADES) == 9103) or (global_var(GVAR_BLADES) == 9102)) 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, 49);
		end
		critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_AI_PACKET, AI_REGULATORS);
		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 == 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

procedure critter_p_proc
begin
	if (hostile1) then begin
		hostile1 := 0;
		attack_complex(dude_obj, 0, 1, 0, 0, 30000, 0, 0);
	end
	else begin
		if (tile_distance_objs(dude_obj, self_obj) > get_critter_stat(dude_obj, 1)) then begin
			set_obj_visibility(self_obj, 1);
		end
		else begin
			set_obj_visibility(self_obj, 0);
		end
	end
end

procedure damage_p_proc
begin
	if (source_obj == dude_obj) then begin
		set_global_var(GVAR_ENEMY_ADYTUM, 1);
		critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_TEAM_NUM, 49);
	end
end

procedure destroy_p_proc
begin
	if (source_obj == dude_obj) then begin
		set_global_var(GVAR_ENEMY_ADYTUM, 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
		critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_TEAM_NUM, 49);
	end
end

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

procedure pickup_p_proc
begin
	set_global_var(GVAR_ENEMY_ADYTUM, 1);
end

procedure talk_p_proc
begin
	start_gdialog(SCRIPT_SAMMAEL, self_obj, 4, -1, -1);
	gsay_start;
	if (local_var(4)) then begin
		call Sammael14;
	end
	else begin
		call Sammael01;
	end
	gsay_end;
	end_dialogue;
end

procedure Sammael01
begin
	gsay_reply(SCRIPT_SAMMAEL, 102);
	giq_option(4, SCRIPT_SAMMAEL, message_str(SCRIPT_SAMMAEL, 103) + proto_data(obj_pid(dude_obj), 1) + message_str(SCRIPT_SAMMAEL, 104), Sammael02, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_SAMMAEL, 105, Sammael03, NEUTRAL_REACTION);
	giq_option(-3, SCRIPT_SAMMAEL, 106, Sammael15, NEUTRAL_REACTION);
end

procedure Sammael02
begin
	set_local_var(4, 1);
	gsay_reply(SCRIPT_SAMMAEL, 107);
	giq_option(4, SCRIPT_SAMMAEL, 108, Sammael04, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_SAMMAEL, 109, Sammael05, NEUTRAL_REACTION);
end

procedure Sammael03
begin
	gsay_message(SCRIPT_SAMMAEL, 110, NEUTRAL_REACTION);
end

procedure Sammael04
begin
	gsay_reply(SCRIPT_SAMMAEL, 111);
	giq_option(4, SCRIPT_SAMMAEL, 112, Sammael06, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_SAMMAEL, 113, Sammael07, NEUTRAL_REACTION);
	giq_option(6, SCRIPT_SAMMAEL, 114, Sammael08, NEUTRAL_REACTION);
	giq_option(0, SCRIPT_SAMMAEL, 115, Sammael05, NEUTRAL_REACTION);
end

procedure Sammael05
begin
	gsay_message(SCRIPT_SAMMAEL, 116, NEUTRAL_REACTION);
end

procedure Sammael06
begin
	gsay_reply(SCRIPT_SAMMAEL, 117);
	giq_option(4, SCRIPT_SAMMAEL, 118, Sammael07, NEUTRAL_REACTION);
	giq_option(6, SCRIPT_SAMMAEL, 119, Sammael08, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_SAMMAEL, 120, Sammael05, NEUTRAL_REACTION);
end

procedure Sammael07
begin
	gsay_message(SCRIPT_SAMMAEL, 121, NEUTRAL_REACTION);
end

procedure Sammael08
begin
	gsay_reply(SCRIPT_SAMMAEL, 122);
	giq_option(4, SCRIPT_SAMMAEL, 123, Sammael09, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_SAMMAEL, 124, Sammael10, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_SAMMAEL, 125, Sammael11, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_SAMMAEL, 126, Sammael12, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_SAMMAEL, 127, Sammael13, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_SAMMAEL, 128, Sammael05, NEUTRAL_REACTION);
end

procedure Sammael09
begin
	gsay_message(SCRIPT_SAMMAEL, 129, NEUTRAL_REACTION);
	call Sammael08;
end

procedure Sammael10
begin
	gsay_message(SCRIPT_SAMMAEL, 130, NEUTRAL_REACTION);
	gsay_message(SCRIPT_SAMMAEL, 131, NEUTRAL_REACTION);
	call Sammael08;
end

procedure Sammael11
begin
	gsay_message(SCRIPT_SAMMAEL, 132, NEUTRAL_REACTION);
	call Sammael08;
end

procedure Sammael12
begin
	gsay_message(SCRIPT_SAMMAEL, 133, NEUTRAL_REACTION);
	call Sammael08;
end

procedure Sammael13
begin
	gsay_message(SCRIPT_SAMMAEL, 134, NEUTRAL_REACTION);
	gsay_message(SCRIPT_SAMMAEL, 135, NEUTRAL_REACTION);
	call Sammael08;
end

procedure Sammael14
begin
	gsay_reply(SCRIPT_SAMMAEL, 136);
	giq_option(4, SCRIPT_SAMMAEL, 137, Sammael04, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_SAMMAEL, 138, Sammael05, NEUTRAL_REACTION);
end

procedure Sammael15
begin
	gsay_message(SCRIPT_SAMMAEL, 139, NEUTRAL_REACTION);
end