#include <define.h>

//#define NAME                    SCRIPT_

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



procedure start;
#include <push.h>

variable HOSTILE;
variable DISGUISED;
variable only_once := 1;


procedure start
begin
	if (only_once) then begin
		only_once := 0;
		critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_TEAM_NUM, 34);
		anim(self_obj, 1000, rotation_to_tile(tile_num(self_obj), 28113));
	end
	else begin
		if (script_action == pickup_proc) then begin
			HOSTILE := 1;
		end
	end
	if (script_action == critter_proc) then begin
		if (HOSTILE) then begin
			HOSTILE := 0;
			attack_complex(dude_obj, 0, 1, 0, 0, 30000, 0, 0);
		end
		if (obj_can_see_obj(self_obj, dude_obj)) then begin
			DISGUISED := 0;
			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
			if (DISGUISED == 0) then begin
				HOSTILE := 1;
			end
		end
	end
	else begin
		if ((script_action == look_at_proc) or (script_action == description_proc)) then begin
			script_overrides;
		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
		end
	end
end