local sim_objects_registry = nil local props_ini = ini_file("misc\\simulation_objects_props.ltx") class "simulation_objects_registry" function simulation_objects_registry:__init() self.objects = {} end function simulation_objects_registry:register(obj) self:get_props(obj) self:update_avaliability(obj) end function simulation_objects_registry:update_avaliability(obj) if xr_logic.pick_section_from_condlist(db.actor or alife():actor(), obj, obj.sim_avail) == "true" and obj:sim_available() then self.objects[obj.id] = obj else self.objects[obj.id] = nil end end function simulation_objects_registry:get_props(obj) obj.props = {} local props_section = obj:name() if obj:clsid() == clsid.online_offline_group_s then props_section = obj:section_name() end if not props_ini:section_exist(props_section) then -- abort("!!!!Warning : object [%s] has no simulation props section!!!!!!!!!!!!!!!!", obj:name()) props_section = "default" if obj:clsid() == clsid.online_offline_group_s then props_section = "default_squad" end if obj:clsid() == clsid.script_actor then props_section = "actor" end end local n = props_ini:line_count(props_section) for j=0,n-1 do local result, prop_name, prop_condlist = props_ini:r_line(props_section,j,"","") if prop_name == "sim_avail" then obj.sim_avail = xr_logic.parse_condlist(nil, "simulation_object", "sim_avail", prop_condlist) else obj.props[prop_name] = prop_condlist end end if obj.sim_avail == nil then obj.sim_avail = xr_logic.parse_condlist(nil, "simulation_object", "sim_avail", "true") end end function simulation_objects_registry:unregister(obj) self.objects[obj.id] = nil end function get_sim_obj_registry() if sim_objects_registry == nil then sim_objects_registry = simulation_objects_registry() end return sim_objects_registry end --*********************************************************************************************** --* SIMULATION_LOCAL_FUNCTIONS * --*********************************************************************************************** function sim_dist_to(obj1 , obj2) local pos1,lv1,gv1 = obj1:get_location() local pos2,lv2,gv2 = obj2:get_location() return utils.graph_distance(gv1, gv2) end local function evaluate_prior_by_dist(target, squad) local dist = sim_dist_to(target, squad) if dist < 1 then dist = 1 end return 1 + 1/dist end function is_on_the_same_level(obj1, obj2) return game_graph():vertex(obj1.m_game_vertex_id):level_id() == game_graph():vertex(obj2.m_game_vertex_id):level_id() end function evaluate_prior(target, squad) local prior = 0 if not target:target_precondition(squad) or not is_on_the_same_level(target, squad) then return prior else prior = 3 end for k,v in pairs (squad.behaviour) do local squad_koeff = tonumber(v) local target_koeff = 0 if target.props[k] ~= nil then target_koeff = tonumber(target.props[k]) end prior = prior + squad_koeff*target_koeff end return prior*evaluate_prior_by_dist(target, squad) end --*********************************************************************************************** --* DEBUG_FUNCTIONS --***********************************************************************************************