--[[----------------------------------------------------------------------------------------------------------
Схема, ведущяя сталкера к месту его работы под smart terrain.
Приводит сталкера к месту работы единожды. Дальше сталкер ходит под обычными схемами.
Чугай Александр (chugai)
------------------------------------------------------------------------------------------------------------]]

-- свойство "дошёл ли сталкер к месту работы?"

class "evaluator_reached_strn_job_location" ( property_evaluator )

function evaluator_reached_strn_job_location:__init( name, glob_stor ) super ( nil, name )
	self.gst = glob_stor
	self.board = sim_board.get_sim_board()
end
function evaluator_reached_strn_job_location:evaluate()
	local smart = self.board.smarts_by_names[self.gst.gulag_name]
	if smart == nil or smart.npc_info[self.object:id()].begin_job == true then
		return true
	end
	return false
--[[
	local npc_li  = alife():level_name(game_graph():vertex(self.object:game_vertex_id()):level_id())	
	local smart_li = smart.smart_level

	if npc_li ~= smart_li then
		return false
	end

	local npc_lvi = self.object:level_vertex_id()


		v.game_vertex_id = patrol:game_vertex_id(0)
		--printf("5b")
		v.level_id		 = game_graph():vertex(v.game_vertex_id):level_id()
			
	if self.object:level_vertex_id() == self.gst.gulag:obj_job_location( self.object:id() ) then


	
			smart:beginJob(self.object:id())
			return true
	end
	return false
	]]
end

--------------------------------------------------------------------------------------------------------------
-- действие "довести сталкера к месту работы"

class "action_reach_strn_job_location" ( action_base )

function action_reach_strn_job_location:__init( name, glob_stor )  super ( nil, name )
	self.gst = glob_stor
	self.board = sim_board.get_sim_board()
end
function action_reach_strn_job_location:initialize()
	action_base.initialize( self )

    self.object:set_desired_direction   ()
	self.object:set_detail_path_type    ( move.line )
	self.object:set_path_type           ( game_object.level_path )

end
function action_reach_strn_job_location:execute()
	local smart = self.board.smarts_by_names[self.gst.gulag_name]
	local job_data = smart.job_data[smart.npc_info[self.object:id()].job_id]

	local v_id = patrol(job_data.alife_path):level_vertex_id(job_data.alife_point)
	self.object:set_dest_level_vertex_id( v_id )
	state_mgr.set_state( self.object, "assault" )

	action_base.execute( self )
end
function action_reach_strn_job_location:finalize()
	action_base.finalize( self )
end

--------------------------------------------------------------------------------------------------------------

function add_to_binder( npc )
	local gst = db.storage[npc:id()]

   	local manager = npc:motivation_action_manager()

	manager:add_evaluator( xr_evaluators_id.reached_strn_job_location, evaluator_reached_strn_job_location( "reached_strn_job_location", gst ) )

	local action = action_reach_strn_job_location( "reach_strn_job_location", gst )
	action:add_precondition( world_property( stalker_ids.property_alive,                  true  ) )
	action:add_precondition( world_property( stalker_ids.property_enemy,                  false ) )
	action:add_precondition( world_property( stalker_ids.property_danger,                 false ) )
	action:add_precondition( world_property( stalker_ids.property_anomaly,                false ) )
	action:add_precondition( world_property( xr_evaluators_id.reached_strn_job_location,  false ) )
	action:add_effect      ( world_property( xr_evaluators_id.reached_strn_job_location,  true  ) )
	manager:add_action( xr_actions_id.reach_strn_job_location, action )

	action = manager:action( xr_actions_id.alife )
	action:add_precondition( world_property( xr_evaluators_id.reached_strn_job_location,  true  ) )
end
