--- Locations and Areas -- @module locs local locations = {} locations.init = function(main_name,template_name) global.main_surface = game.surfaces[main_name] global.template_surface = game.surfaces[template_name] global.main_surface.always_day = true global.template_surface.always_day = true end locations.get_surface_ent_from_tag = function(surface,tag) --print("getting tag "..tag) local ent = game.get_entity_by_tag(tag) if ent then local target = surface.find_entities_filtered({ name = ent.name, force = ent.force, position = ent.position }) if target[1] then return target[1] end end --print("Cant find tagged entity on surface, providing template for "..tag) return ent or nil end locations.get_pos = function(pos_name) if global.template_surface.get_script_positions(pos_name)[1] then return global.template_surface.get_script_positions(pos_name)[1].position end return nil end locations.get_area = function(area_name) if global.template_surface.get_script_areas(area_name)[1] then return global.template_surface.get_script_areas(area_name)[1].area end return nil end locations.get_structure_in_area = function(structure_name,area_name) local area = locations.get_area(area_name) local structure = global.main_surface.find_entities_filtered({ name=structure_name, area=area }) return structure[1] or nil end locations.find_fixed_recipe_in_area = function(recipe_name,area_name) local area = locations.get_area(area_name) local structures = global.main_surface.find_entities_filtered({ name='escape-pod-assembler', area=area }) for _, structure in pairs(structures) do if structure.get_recipe().name == recipe_name then return structure end end return nil end return locations