-- Scan around the Mobile Factory for the Sync Area -- function MF:syncAreaScan() self.clonedResourcesTable = {} -- Cloning Tiles -- local radius = _mfSyncAreaRadius + 1 local bdb = {{self.ent.position.x - radius, self.ent.position.y - radius},{self.ent.position.x + radius, self.ent.position.y + radius}} local clonedBdb = {{_mfSyncAreaPosition.x - radius, _mfSyncAreaPosition.y - radius},{_mfSyncAreaPosition.x + radius, _mfSyncAreaPosition.y + radius}} local inside = self.fS local outside = self.ent.surface local obstructed = false local distancesInBools = {} local distancesOutBools = {} -- Look for Entities inside the Sync Area -- local entTableIn = inside.find_entities_filtered{area = clonedBdb} -- Check if Entities inside Can't be Placed Outside -- for k, ent in pairs(entTableIn) do -- may not need to do the if local posX = math.floor(self.ent.position.x) + (ent.position.x - _mfSyncAreaPosition.x) local posY = math.floor(self.ent.position.y) + (ent.position.y - _mfSyncAreaPosition.y) distancesInBools[k] = Util.distance(ent.position, _mfSyncAreaPosition) < _mfSyncAreaRadius --if outside.entity_prototype_collides(ent.name, {posX, posY}, false, ent.direction) == true then -- if we can place it, including marking obstructions for deconstruction... would overlap entities if we have friendly chests etc on the other side if outside.can_place_entity{name = ent.name, position = {posX, posY}, direction = ent.direction, force = ent.force, build_check_type = defines.build_check_type.ghost_place, forced = true} == false then obstructed = true break end end if obstructed == true then local player = nil if self.player ~= "" then player = getPlayer(self.player) if player.connected then player.create_local_flying_text{text={"info.MF-sync-collision"}, position = self.ent.position} end end return end -- Look for Entities around the Mobile Factory -- local entTableOut = outside.find_entities_filtered{area = bdb} -- Check if Entities inside Can't be Placed Iutside -- for k, ent in pairs(entTableOut) do local posX = (ent.position.x - math.floor(self.ent.position.x)) + _mfSyncAreaPosition.x local posY = (ent.position.y - math.floor(self.ent.position.y)) + _mfSyncAreaPosition.y distancesOutBools[k] = Util.distance(ent.position, {math.floor(self.ent.position.x), math.floor(self.ent.position.y)}) < _mfSyncAreaRadius if _mfSyncAreaAllowedTypes[ent.type] == true and distancesOutBools[k] == true then if inside.entity_prototype_collides(ent.name, {posX, posY}, false) == true then obstructed = true break end end end if obstructed == true then local player = nil if self.player ~= "" then player = getPlayer(self.player) if player.connected then player.create_local_flying_text{text={"info.MF-sync-collision"}, position = self.ent.position} end end return end -- Clone Area to Sync Area -- -- cloning the area can destroy inside entities (invalid tile placement), thus we checked first outside.clone_area{source_area=bdb, destination_area=clonedBdb, destination_surface=inside, clone_entities=false, clone_decoratives=false, clear_destination_entities=false} createSyncAreaMFSurface(inside) -- Clone Outside Entities -- for k, ent in pairs(entTableOut) do if _mfSyncAreaAllowedTypes[ent.type] == true and distancesOutBools[k] == true then self:cloneEntity(ent, "in") end end -- Clone Inside Entities -- for k, ent in pairs(entTableIn) do if _mfSyncAreaAllowedTypes[ent.type] == true and distancesInBools[k] == true then self:cloneEntity(ent, "out") end if ent.type == "mining-drill" then ent.update_connections() end end end