#include <define.h>

//#define NAME                    SCRIPT_

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



procedure start;
#include <push.h>

variable Only_once := 1;
variable Hostile;
variable oktoyell := 1;
variable active;


procedure start
begin
	if (Only_once) then begin
		Only_once := 0;
		critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_TEAM_NUM, 30);
		critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_AI_PACKET, AI_GHOUL_NASTY);
		if (global_var(GVAR_HUB_FILLER_30) == 1) then begin
			active := 1;
			set_obj_visibility(self_obj, 0);
		end
		else begin
			set_obj_visibility(self_obj, 1);
		end
	end
	if (active) then begin
		if (script_action == talk_proc) then begin
			if (global_var(GVAR_NECROP_WATER_PUMP_FIXED) == 2) then begin
				float_msg(self_obj, message_str(SCRIPT_GUARD2, 102), FLOAT_MSG_YELLOW);
			end
			else begin
				float_msg(self_obj, message_str(SCRIPT_GUARD2, 101), FLOAT_MSG_YELLOW);
			end
		end
		else begin
			if (script_action == damage_proc) then begin
				Hostile := 1;
			end
			else begin
				if (script_action == critter_proc) then begin
					if (global_var(GVAR_ENEMY_NECROPOLIS) and obj_can_see_obj(self_obj, dude_obj)) then begin
						Hostile := 1;
					end
					if (Hostile) then begin
						Hostile := 0;
						set_global_var(GVAR_HUB_FILLER_30, 0);
						set_global_var(GVAR_ENEMY_NECROPOLIS, 1);
						attack_complex(dude_obj, 0, 1, 0, 0, 30000, 0, 0);
					end
					else begin
						if (global_var(GVAR_NECROP_WATER_PUMP_FIXED) != 2) then begin
							if (tile_distance_objs(self_obj, dude_obj) > 7) then begin
								Hostile := 1;
							end
							else begin
								if ((tile_distance_objs(self_obj, dude_obj) > 4) and oktoyell) then begin
									oktoyell := 0;
									float_msg(self_obj, message_str(SCRIPT_GUARD2, 103), FLOAT_MSG_YELLOW);
								end
								else begin
									if (tile_distance_objs(self_obj, dude_obj) < 5) then begin
										oktoyell := 1;
									end
								end
							end
						end
					end
				end
				else begin
					if (script_action == pickup_proc) then begin
						Hostile := 1;
					end
					else begin
						if (script_action == look_at_proc) then begin
							script_overrides;
							display_msg(message_str(SCRIPT_GUARD2, 100));
						end
						else begin
							if (script_action == destroy_proc) then begin
								set_global_var(GVAR_GARRET_STATUS, 3);
								set_global_var(GVAR_HUB_FILLER_30, 0);
								set_global_var(GVAR_ENEMY_NECROPOLIS, 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_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
			end
		end
	end
end