--on_activate

local set_up_timer = defense_mob_api.library.set_up_timer
local do_observers = defense_mob_api.library.set_up_observers("register_on_activate")

--make idle sound every so many seconds
local make_sound = defense_mob_api.library.make_sound
local function make_idle_sound(self, dtime)
	make_sound(self, "idle")
	return true, math.random() * 5 + 4
end

-- Remove when far enough and may not reach the player at all
local function remove_when_far(self, dtime)
	--THIS MIGHT BREAK WITH WEAK TARGET FUNCTION
	local should_remove = self.target.distance > 12
	if should_remove
	then
		self:remove()
	end
	return not should_remove, 20
end


function defense_mob_api.library.on_activate(self, staticdata)
	do_observers(self, staticdata)
	self.timers = {}
	
	--idle sound timer
	set_up_timer(self, math.random(5), make_idle_sound, "idle_sound")
	--life timer
	set_up_timer(self, 70, remove_when_far, "remove_when_far")
	
	self.object:set_armor_groups({fleshy = 100 - self.armor})
	if self.movement ~= "air"
	then
		self.object:setacceleration({x = 0, y = self.gravity, z = 0})
	end
	self.id = math.random(0, 100000)
end
