function init(obj)
	printf("_bp: init(): name='%s'", obj:name())

	db.storage[obj:id()] = { }
	local new_binder = signal_light_binder(obj)
	obj:bind_object(new_binder)
end

---------------------------------------------------------------------------------------------
class "signal_light_binder" (object_binder)
function signal_light_binder:__init(obj) super(obj)
    self.need_turn_off = true
--	self.initialized = false
	self.loaded = false
end

function signal_light_binder:reload(section)
	object_binder.reload(self, section)
end

function signal_light_binder:reinit()
	object_binder.reinit(self)
	db.signal_light[self.object:name()] = self
end

function signal_light_binder:update(delta)
	object_binder.update(self, delta)

    local obj = self.object
	if self.start_time == nil then
        if self.need_turn_off then
			obj:get_hanging_lamp():turn_off()
			self.need_turn_off = false
			self.loaded = false
		end
		return
	end

	local fly_time = time_global() - self.start_time
	if self.loaded then
		self.start_time = self.start_time + time_global() - self.delta_time
        self.delta_time = nil
		self.loaded = false
		fly_time = time_global() - self.start_time
		if fly_time < 1500 then
	        obj:set_const_force(vector():set(0,1,0), 180+math.floor(fly_time/5), 1500-fly_time)
			obj:start_particles("weapons\\light_signal", "link")
		elseif fly_time < 20000 then
	        obj:set_const_force(vector():set(0,1,0), 33, 20000-fly_time)
			obj:start_particles("weapons\\light_signal", "link")
		end
		return
	end
	-- Главный цикл полета сигналки
	if fly_time > 21500 then
		self:stop_fly()
		return
	end

	if fly_time > 1500 then
		if self.slow_fly_started ~= true then
			self:slow_fly()
		end
	end

end

function signal_light_binder:net_spawn(data)
	if not object_binder.net_spawn(self, data) then
		return false
	end
	return true
end

function signal_light_binder:net_destroy()
	db.signal_light[self.object:name()] = nil
	object_binder.net_destroy(self)
end

function signal_light_binder:launch()
	if not(db.actor~=nil and (level.get_time_hours() < 3 or level.get_time_hours() > 22)) then
		return false
	end

	if self.start_time ~= nil then
		return false
	end

	local obj = self.object
	obj:set_const_force(vector():set(0,1,0), 180, 1500)
	obj:start_particles("weapons\\light_signal", "link")
	obj:get_hanging_lamp():turn_on()

	self.start_time = time_global()
	self.slow_fly_started = false
	return true
end

function signal_light_binder:slow_fly()
	self.slow_fly_started = true
	self.object:set_const_force(vector():set(0,1,0), 30, 20000)
end

function signal_light_binder:stop_fly()
	self.start_time = nil
	self.slow_fly_started = false

	local obj = self.object
	obj:stop_particles("weapons\\light_signal", "link")
 	obj:get_hanging_lamp():turn_off()
end

function signal_light_binder:is_flying()
	return self.start_time ~= nil
end

-- Standart function for save
function signal_light_binder:net_save_relevant()
	return true
end

function signal_light_binder:save(packet)
	set_save_marker(packet, "save", false, "signal_light_binder")
	object_binder.save(self, packet)
	if self.start_time == nil then
		packet:w_u32(-1)
	else
		packet:w_u32(time_global()-self.start_time)
	end
    packet:w_bool(self.slow_fly_started==true)
	set_save_marker(packet, "save", true, "signal_light_binder")
end

function signal_light_binder:load(reader)
	set_save_marker(reader, "load", false, "signal_light_binder")
	object_binder.load(self, reader)
	local time = reader:r_u32()
	if time ~= 4294967296 then
		self.start_time = time_global() - time
	end
    self.slow_fly_started = reader:r_bool()
	self.loaded = true
	self.delta_time = time_global()
	set_save_marker(reader, "load", true, "signal_light_binder")
end
