#include <define.h>

//#define NAME                    SCRIPT_

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


variable Hostile;
variable init_teams;
variable Times;

procedure start;
#include <push.h>


procedure start
begin
	if (not(init_teams)) then begin
		critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_TEAM_NUM, 34);
		init_teams := 1;
	end
	else begin
		if (script_action == pickup_proc) then begin
			Hostile := 1;
		end
	end
	if (script_action == critter_proc) then begin
		if (global_var(GVAR_NECROPOLIS_INVADED) == 0) then begin
			set_obj_visibility(self_obj, 1);
		end
		else begin
			if (Hostile) then begin
				Hostile := 0;
				attack_complex(dude_obj, 0, 1, 0, 0, 30000, 0, 0);
			end
			if ((tile_num(self_obj) != 16929) and (Times == 0)) then begin
				Times := 1;
				animate_move_obj_to_tile(self_obj, 16929, ANIMATE_WALK);
				add_timer_event(self_obj, game_ticks(60), 1);
			end
		end
	end
	else begin
		if (script_action == timed_event_proc) then begin
			if (fixed_param == 1) then begin
				animate_move_obj_to_tile(self_obj, 10917, ANIMATE_WALK);
				add_timer_event(self_obj, game_ticks(60), 2);
			end
			else begin
				if (fixed_param == 2) then begin
					animate_move_obj_to_tile(self_obj, 16929, ANIMATE_WALK);
					add_timer_event(self_obj, game_ticks(60), 1);
				end
			end
		end
		else begin
			if (script_action == look_at_proc) then begin
				script_overrides;
				display_msg(message_str(SCRIPT_MUTANT5, 100));
			end
			else begin
				if (script_action == destroy_proc) then begin
					set_global_var(GVAR_SUPER_MUTANTS_KILLED, global_var(GVAR_SUPER_MUTANTS_KILLED) + 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