#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 zamin;
procedure goto00;

variable hostile1;
variable Only_Once := 1;
variable DISGUISED;
variable ARMED;
variable rndx;


procedure start
begin
	if (Only_Once) then begin
		Only_Once := 0;
		critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_TEAM_NUM, 34);
		critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_AI_PACKET, AI_CHILDREN_TRUE);
	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
				end
			end
		end
	end
end

procedure combat
begin
	hostile1 := 1;
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 pickup_p_proc
begin
	if (source_obj == dude_obj) then begin
		hostile1 := 1;
	end
end

procedure talk_p_proc
begin
	call zamin;
	if ((DISGUISED == 1) and (ARMED == 0)) then begin
		call goto00;
	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;
end

procedure zamin
begin
	DISGUISED := 0;
	ARMED := 0;
	if ((obj_item_subtype(critter_inven_obj(dude_obj, 1)) == 3) or (obj_item_subtype(critter_inven_obj(dude_obj, 2)) == 3)) then begin
		ARMED := 1;
	end
	if (obj_pid(critter_inven_obj(dude_obj, 0)) == 113) then begin
		if (metarule(16, 0) > 1) then begin
			DISGUISED := 0;
		end
		else begin
			DISGUISED := 1;
		end
	end
end

procedure goto00
begin
	rndx := random(1, 3);
	if (rndx == 3) then begin
		if (dude_is_male) then begin
			float_msg(self_obj, message_str(SCRIPT_SMPRAY, 106), FLOAT_MSG_RED);
		end
		else begin
			float_msg(self_obj, message_str(SCRIPT_SMPRAY, 107), FLOAT_MSG_RED);
		end
	end
	else begin
		if (rndx == 2) then begin
			float_msg(self_obj, message_str(SCRIPT_SMPRAY, 105), FLOAT_MSG_RED);
		end
		else begin
			float_msg(self_obj, message_str(SCRIPT_SMPRAY, 108), FLOAT_MSG_RED);
		end
	end
end