--TODO: make API to manipulate timers
function defense_mob_api.library.set_up_timer(self, time, callback, name)
	if self.timers[name]
	then
		self.timers[name].manipulate_time(self, -time)
		return
	end
	
	local elapsed = 0
	local elapsed_after = time
	local index = #self.timers + 1
	
	local function manipulate_time(self, reduction, cap)
		local newelapsed = elapsed + reduction
		if newelapsed < (cap or math.huge)
		then
			elapsed = newelapsed
		end
		if elapsed >= elapsed_after
		then
			local continue, continue_for = callback(self, elapsed_after)
			
			if continue
			then
				elapsed_after = continue_for
				elapsed = 0
			else
				table.remove(self.timers, index)
				self.timers[name] = nil
			end
		end
	end
	
	local function get_remaining_time()
		return elapsed_after - elapsed
	end
	
	local this =
	{
		manipulate_time = manipulate_time,
		get_remaining_time = get_remaining_time,
	}
	
	table.insert(self.timers, this)
	self.timers[name] = this
end

