function printf()
end
--' Смотрим ли мы сейчас туда, куда нужно или нет?
class "eva_state_mgr_direction" (property_evaluator)
function eva_state_mgr_direction:__init(name, st) super (nil, name)
	self.st = st
end
function eva_state_mgr_direction:evaluate()
    local sight_type = self.object:sight_params()
    
	-- Если задан объект на который смотреть
	if self.st.look_object ~= nil then
		if sight_type.m_object == nil or
           sight_type.m_object:id() ~= self.st.look_object or
		   self.st.point_obj_dir ~= look_object_type(self.object, self.st)
		then
			printf("pl:dir1!!!")
			return false
		end
		
		self:callback()
		printf("pl:dir2!!!")
		return true
	end

	-- Если задана позиция в которую смотреть
	if self.st.look_position ~= nil then
        if sight_type.m_sight_type ~= look_position_type(self.object, self.st) then
        	printf("pl:dir3!!!")
            return false
        end


		local dir = vector():sub(self.st.look_position, self.object:position())
		if look_object_type(self.object, self.st) == true then
			dir.y = 0
		end		
        if utils.vector_cmp_prec(sight_type.m_vector, dir, 0.01) ~= true then
            --printf("%s false vector", self.object:name())
            --printf("%s %s %s", sight_type.m_vector.x, sight_type.m_vector.y, sight_type.m_vector.z)
            --printf("%s %s %s", dir.x, dir.y, dir.z)
			printf("pl:dir4!!!")
            return false
        end

		self:callback()
		printf("pl:dir5!!!")
		return true
	end

	-- Если не задано куда смотреть.
	-- И если мы до этого куда то смотрели
	if sight_type.m_object ~= nil then
		printf("pl:dir6!!!")        
		return false	
	end
		
	--' Или если мы смотрели не так как надо
    if sight_type.m_sight_type ~= look_position_type(self.object, self.st) then
    	printf("pl:dir7!!![%s]", look_position_type(self.object, self.st))
        return false
    end

	self:callback()
	printf("pl:dir8!!!")
	return true
end
function eva_state_mgr_direction:callback()
	if self.st.callback ~= nil and
	   self.st.callback.turn_end_func ~= nil
	then
		self.st.callback.turn_end_func(self.st.callback.obj)
		if self.st.callback ~= nil	then
			self.st.callback.turn_end_func = nil
		end
	end
end

class "eva_state_mgr_direction_search" (property_evaluator)
function eva_state_mgr_direction_search:__init(name, st) super (nil, name)
	self.st = st
end
function eva_state_mgr_direction_search:evaluate()
	if self.st.look_position ~= nil or self.st.look_object ~= nil then
		return false
	end
	return true
end

--' Поворачиваемся ли мы сейчас
class "eva_state_mgr_direction_turning" (property_evaluator)
function eva_state_mgr_direction_turning:__init(name, st) super (nil, name)
	self.st = st
end
function eva_state_mgr_direction_turning:evaluate()
	if self.object:mental_state() == anim.danger then
		return false
	end
	return self.object:is_body_turning()
end



--' Включаем поворот
class "act_state_mgr_direction_turn" (action_base)
function act_state_mgr_direction_turn:__init(name, st) super (nil, name)
	self.st = st
end
function act_state_mgr_direction_turn:initialize()
	--printf("turning object %s ",self.object:name())
	action_base.initialize(self)
	self:turn()
end
function act_state_mgr_direction_turn:execute()
	action_base.execute(self)
	--' Нельзя дергать дирекшн сталкера когда он в смарткавере...
	if db.storage[self.object:id()].active_scheme ~= "smartcover" then
		self:turn()
	end
end
function act_state_mgr_direction_turn:finalize()
	action_base.finalize(self)
end
function act_state_mgr_direction_turn:turn()
	self.st.point_obj_dir = look_object_type(self.object, self.st)
	
	if self.st.look_object ~= nil and
	   level.object_by_id(self.st.look_object) ~= nil 
	then		
		look_at_object(self.object, self.st)
	elseif self.st.look_position ~= nil then
		local dir = vector():sub(self.st.look_position, self.object:position())
		if self.st.point_obj_dir == true then
			dir.y = 0
		end
	--	printf("SET_SIGHT!!!act_state_mgr_direction_turn:turn()")
		self.object:set_sight(look.direction, dir, true)
	end
end


--' Включаем поворот в никуда
class "act_state_mgr_direction_search" (action_base)
function act_state_mgr_direction_search:__init(name, st) super (nil, name)
	self.st = st
end
function act_state_mgr_direction_search:initialize()
	action_base.initialize(self)
	--	printf("SET_SIGHT!!!act_state_mgr_direction_search:initialize()")
    self.object:set_sight(look_position_type(self.object, self.st), nil, 0)
end
function act_state_mgr_direction_search:execute()
	action_base.execute(self)
end
function act_state_mgr_direction_search:finalize()
	action_base.finalize(self)
end

function look_at_object(npc, st)
	st.point_obj_dir = look_object_type(npc, st)
	if st.point_obj_dir == true then
		printf("SET_SIGHT!!!look_at_object(npc, st)1")
		npc:set_sight(level.object_by_id(st.look_object),true, false, true)
	else
		printf("SET_SIGHT!!!look_at_object(npc, st)2")
		npc:set_sight(level.object_by_id(st.look_object),true, true)	
	end									

end

local look_direction_states = {
	threat = true,
	threat_na = true,
	wait_na = true,
	guard_na = true
	}

function look_object_type(npc, st)	
	--' Возвращает true  если нужно смотреть по направлению
	--' false - нужно смотреть на объект
	if look_direction_states[st.target_state] == true then
		return true
	end
	return state_lib.states[st.target_state].animation ~= nil
end

function look_position_type(npc, st)
    if st == nil then
    	printf("1")
        return look.path_dir
    end
--	local anim_props =  state_mgr_animation_list.animations[state_lib.states[st.target_state].animation].prop
--	if anim_props.pos ~= nil and anim_props.rot ~= nil then
--		return CSightParams.eSightTypeAnimationDirection
--	end
	
    --' Для движения
	if not st.planner:evaluator(st.properties["movement_stand"]):evaluate() then
        if st.look_position ~= nil then
        	printf("2")
            return look.direction
        end
		printf("3")
        return look.path_dir       
    end

    --' Смотрим в позицию
    if st.look_position ~= nil then
    	printf("4")
         return look.direction
    end

    --' Никуда не смотрим
    if state_lib.states[st.target_state].direction then
    	printf("5")
		return state_lib.states[st.target_state].direction
    end
	printf("6")
    return look.danger
end

--' поворот
 
function turn(npc, st)
	st.point_obj_dir = look_object_type(npc, st)
	
	if st.look_object ~= nil and
	   level.object_by_id(st.look_object) ~= nil 
	then		
		look_at_object(npc, st)
	elseif st.look_position ~= nil then
		local dir = vector():sub(st.look_position, npc:position())
		if st.point_obj_dir == true then
			dir.y = 0
		end
		printf("SET_SIGHT!!!turn(npc, st)")
		npc:set_sight(look.direction, dir, true)
	end
end
