#include <define.h>

//#define NAME                    SCRIPT_

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



procedure start;
#include <push.h>
procedure critter_p_proc;
procedure destroy_p_proc;
procedure timed_event_p_proc;

variable rndx;
variable rndy;
variable critter_tile;
variable hostile1;
variable only_once := 1;
variable Start_Moving;


procedure start
begin
	if (only_once) then begin
		only_once := 0;
		critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_AI_PACKET, AI_RADSCORPION);
		critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_TEAM_NUM, 5);
	end
	else begin
		if (script_action == combat_proc) then begin
			if (fixed_param == 2) then begin
				if (not(is_success(do_check(dude_obj, 6, -1)))) then begin
					rndx := random(1, 6);
					poison(target_obj, rndx);
				end
			end
		end
		else begin
			if (script_action == destroy_proc) then begin
				call destroy_p_proc;
			end
			else begin
				if (script_action == timed_event_proc) then begin
					call timed_event_p_proc;
				end
				else begin
					if (script_action == critter_proc) then begin
						call critter_p_proc;
					end
				end
			end
		end
	end
end

procedure critter_p_proc
begin
	if ((random(1, 10) == 1) and (Start_Moving == 0)) then begin
		Start_Moving := 1;
		add_timer_event(self_obj, game_ticks(5), 1);
	end
	if (obj_can_see_obj(self_obj, dude_obj)) then begin
		hostile1 := 1;
	end
	if (hostile1) then begin
		hostile1 := 0;
		attack_complex(dude_obj, 0, 1, 0, 0, 30000, 0, 0);
	end
end

procedure destroy_p_proc
begin
	set_global_var(GVAR_NUM_RADSCORPIONS, global_var(GVAR_NUM_RADSCORPIONS) - 1);
	if (global_var(GVAR_NUM_RADSCORPIONS) <= 0) then begin
		set_global_var(GVAR_NUM_RADSCORPIONS, 0);
		set_global_var(GVAR_RADSCORPIONS_KILLED, 2);
		set_global_var(GVAR_RADSCORPION_SEED, 2);
		give_exp_points(500);
		display_msg(message_str(SCRIPT_SSRADSCO, 100));
		set_global_var(GVAR_PLAYER_REPUTATION, global_var(GVAR_PLAYER_REPUTATION) + 6);
	end
end

procedure timed_event_p_proc
begin
	variable LVar0 := 0;
	if (Start_Moving == 1) then begin
		LVar0 := tile_num_in_direction(tile_num(self_obj), random(0, 5), 3);
		Start_Moving := 0;
		reg_anim_func(2, self_obj);
		reg_anim_func(1, 1);
		reg_anim_obj_move_to_tile(self_obj, LVar0, -1);
		reg_anim_func(3, 0);
	end
end