Search in sources :

Example 26 with IRouter

use of logisticspipes.routing.IRouter in project LogisticsPipes by RS485.

the class RequestRoutingLasersPacket method handleRouteInDirection.

private void handleRouteInDirection(final LogisticsTileGenericPipe pipeIn, EnumFacing dirIn, ArrayList<ExitRoute> connectedRoutersIn, final List<LaserData> lasersIn, EnumSet<PipeRoutingConnectionType> connectionTypeIn, final Log logIn) {
    List<DataEntry> worklist = new LinkedList<>();
    worklist.add(new DataEntry(pipeIn, dirIn, connectedRoutersIn, lasersIn, connectionTypeIn, logIn));
    while (!worklist.isEmpty()) {
        final DataEntry entry = worklist.remove(0);
        final LogisticsTileGenericPipe pipe = entry.pipe;
        final EnumFacing dir = entry.dir;
        final ArrayList<ExitRoute> connectedRouters = entry.connectedRouters;
        final List<LaserData> lasers = entry.lasers;
        final EnumSet<PipeRoutingConnectionType> connectionType = entry.connectionType;
        final Log log = entry.log;
        if (LogisticsPipes.isDEBUG()) {
            log.log("Size: " + connectedRouters.size());
        }
        lasers.add(new LaserData(pipe.getX(), pipe.getY(), pipe.getZ(), dir, connectionType).setStartPipe(firstPipe));
        firstPipe = false;
        HashMap<CoreRoutedPipe, ExitRoute> map = PathFinder.paintAndgetConnectedRoutingPipes(pipe, dir, Configs.LOGISTICS_DETECTION_COUNT, Configs.LOGISTICS_DETECTION_LENGTH, (world, laser) -> {
            if (pipe.getWorld() == world) {
                lasers.add(laser);
            }
        }, connectionType);
        for (CoreRoutedPipe connectedPipe : map.keySet()) {
            IRouter newRouter = connectedPipe.getRouter();
            Iterator<ExitRoute> iRoutes = connectedRouters.iterator();
            while (iRoutes.hasNext()) {
                ExitRoute route = iRoutes.next();
                if (route.destination == newRouter) {
                    iRoutes.remove();
                }
            }
        }
        Map<CoreRoutedPipe, ArrayList<ExitRoute>> sort = new HashMap<>();
        for (ExitRoute routeTo : connectedRouters) {
            ExitRoute result = null;
            CoreRoutedPipe resultPipe = null;
            for (Entry<CoreRoutedPipe, ExitRoute> routeCanidate : map.entrySet()) {
                List<ExitRoute> distances = routeCanidate.getValue().destination.getDistanceTo(routeTo.destination);
                for (ExitRoute distance : distances) {
                    if (distance.isSameWay(routeTo)) {
                        if (result == null || result.distanceToDestination > distance.distanceToDestination) {
                            result = distance;
                            resultPipe = routeCanidate.getKey();
                        }
                    }
                }
            }
            if (result == null) {
                continue;
            }
            if (!sort.containsKey(resultPipe)) {
                sort.put(resultPipe, new ArrayList<>());
            }
            if (!sort.get(resultPipe).contains(result)) {
                sort.get(resultPipe).add(result);
            }
        }
        for (Entry<CoreRoutedPipe, ArrayList<ExitRoute>> connectedPipe : sort.entrySet()) {
            HashMap<EnumFacing, ArrayList<ExitRoute>> routers = new HashMap<>();
            for (ExitRoute exit : connectedPipe.getValue()) {
                if (!routers.containsKey(exit.exitOrientation)) {
                    routers.put(exit.exitOrientation, new ArrayList<>());
                }
                if (!routers.get(exit.exitOrientation).contains(exit)) {
                    routers.get(exit.exitOrientation).add(exit);
                }
            }
            for (final EnumFacing exitDir : routers.keySet()) {
                if (exitDir == null) {
                    continue;
                }
                worklist.add(new DataEntry(connectedPipe.getKey().container, exitDir, routers.get(exitDir), lasers, map.get(connectedPipe.getKey()).connectionDetails, new Log() {

                    @Override
                    void log(String logString) {
                        if (LogisticsPipes.isDEBUG()) {
                            log.log(exitDir.name() + ": " + logString);
                        }
                    }
                }));
            }
        }
    }
}
Also used : PipeRoutingConnectionType(logisticspipes.routing.PipeRoutingConnectionType) HashMap(java.util.HashMap) EnumFacing(net.minecraft.util.EnumFacing) ArrayList(java.util.ArrayList) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) IRouter(logisticspipes.routing.IRouter) LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe) LinkedList(java.util.LinkedList) LaserData(logisticspipes.routing.LaserData) ExitRoute(logisticspipes.routing.ExitRoute)

Example 27 with IRouter

use of logisticspipes.routing.IRouter in project LogisticsPipes by RS485.

the class ModuleCrafter method getSatelliteNameForUUID.

private String getSatelliteNameForUUID(UUID uuid) {
    if (UUIDPropertyKt.isZero(uuid)) {
        return "";
    }
    int simpleId = SimpleServiceLocator.routerManager.getIDforUUID(uuid);
    IRouter router = SimpleServiceLocator.routerManager.getRouter(simpleId);
    if (router != null) {
        CoreRoutedPipe pipe = router.getPipe();
        if (pipe instanceof PipeItemsSatelliteLogistics) {
            return ((PipeItemsSatelliteLogistics) pipe).getSatellitePipeName();
        } else if (pipe instanceof PipeFluidSatellite) {
            return ((PipeFluidSatellite) pipe).getSatellitePipeName();
        }
    }
    return "UNKNOWN NAME";
}
Also used : PipeItemsSatelliteLogistics(logisticspipes.pipes.PipeItemsSatelliteLogistics) IRouter(logisticspipes.routing.IRouter) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) PipeFluidSatellite(logisticspipes.pipes.PipeFluidSatellite)

Example 28 with IRouter

use of logisticspipes.routing.IRouter in project LogisticsPipes by RS485.

the class LogisticsManager method assignDestinationFor.

/**
 * Will assign a destination for a IRoutedItem based on a best sink reply
 * recieved from other pipes.
 *
 * @param item
 *            The item that needs to be routed.
 * @param sourceRouterID
 *            The SimpleID of the pipe that is sending the item. (the
 *            routedItem will cache the UUID, and that the SimpleID belongs
 *            to the UUID will be checked when appropriate)
 * @param excludeSource
 *            Boolean, true means that it wont set the source as the
 *            destination.
 * @return IRoutedItem with a newly assigned destination
 */
@Override
public IRoutedItem assignDestinationFor(IRoutedItem item, int sourceRouterID, boolean excludeSource) {
    // Assert: only called server side.
    // If we for some reason can't get the router we can't do anything either
    IRouter sourceRouter = SimpleServiceLocator.routerManager.getServerRouter(sourceRouterID);
    if (sourceRouter == null) {
        return item;
    }
    // Wipe current destination
    item.clearDestination();
    final ItemIdentifierStack itemIdStack = item.getItemIdentifierStack();
    if (itemIdStack == null) {
        return item;
    }
    BitSet routersIndex = ServerRouter.getRoutersInterestedIn(itemIdStack.getItem());
    // get the routing table
    List<ExitRoute> validDestinations = new ArrayList<>();
    for (int i = routersIndex.nextSetBit(0); i >= 0; i = routersIndex.nextSetBit(i + 1)) {
        IRouter r = SimpleServiceLocator.routerManager.getServerRouter(i);
        List<ExitRoute> exits = sourceRouter.getDistanceTo(r);
        if (exits != null) {
            validDestinations.addAll(exits.stream().filter(e -> e.containsFlag(PipeRoutingConnectionType.canRouteTo)).collect(Collectors.toList()));
        }
    }
    Collections.sort(validDestinations);
    final ItemStack stack = itemIdStack.makeNormalStack();
    if (stack.getItem() instanceof LogisticsFluidContainer) {
        Pair<Integer, FluidSinkReply> bestReply = SimpleServiceLocator.logisticsFluidManager.getBestReply(SimpleServiceLocator.logisticsFluidManager.getFluidFromContainer(itemIdStack), sourceRouter, item.getJamList());
        if (bestReply != null) {
            item.setDestination(bestReply.getValue1());
        }
    } else {
        Triplet<Integer, SinkReply, List<IFilter>> bestReply = getBestReply(stack, itemIdStack.getItem(), sourceRouter, validDestinations, excludeSource, item.getJamList(), null, true);
        if (bestReply.getValue1() != null && bestReply.getValue1() != 0) {
            item.setDestination(bestReply.getValue1());
            if (bestReply.getValue2().isPassive) {
                if (bestReply.getValue2().isDefault) {
                    item.setTransportMode(TransportMode.Default);
                } else {
                    item.setTransportMode(TransportMode.Passive);
                }
            } else {
                item.setTransportMode(TransportMode.Active);
            }
            item.setAdditionalTargetInformation(bestReply.getValue2().addInfo);
        }
    }
    return item;
}
Also used : BitSet(java.util.BitSet) ArrayList(java.util.ArrayList) FluidSinkReply(logisticspipes.utils.FluidSinkReply) LogisticsFluidContainer(logisticspipes.items.LogisticsFluidContainer) IRouter(logisticspipes.routing.IRouter) SinkReply(logisticspipes.utils.SinkReply) FluidSinkReply(logisticspipes.utils.FluidSinkReply) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) ExitRoute(logisticspipes.routing.ExitRoute) ItemStack(net.minecraft.item.ItemStack)

Example 29 with IRouter

use of logisticspipes.routing.IRouter in project LogisticsPipes by RS485.

the class CoreRoutedPipe method getPipeForUUID.

@CCCommand(description = "Returns the access to the pipe of the given router UUID")
@ModDependentMethod(modId = LPConstants.computerCraftModID)
@CCDirectCall
public Object getPipeForUUID(String sUuid) throws PermissionException {
    if (!getUpgradeManager().hasCCRemoteControlUpgrade()) {
        throw new PermissionException();
    }
    UUID uuid = UUID.fromString(sUuid);
    int id = SimpleServiceLocator.routerManager.getIDforUUID(uuid);
    IRouter router = SimpleServiceLocator.routerManager.getRouter(id);
    if (router == null) {
        return null;
    }
    return router.getPipe();
}
Also used : PermissionException(logisticspipes.security.PermissionException) IRouter(logisticspipes.routing.IRouter) UUID(java.util.UUID) ModDependentMethod(logisticspipes.asm.ModDependentMethod) CCCommand(logisticspipes.proxy.computers.interfaces.CCCommand) CCDirectCall(logisticspipes.proxy.computers.interfaces.CCDirectCall)

Example 30 with IRouter

use of logisticspipes.routing.IRouter in project LogisticsPipes by RS485.

the class CoreRoutedPipe method doDebugStuff.

private void doDebugStuff(EntityPlayer entityplayer) {
    // entityplayer.world.setWorldTime(4951);
    if (!MainProxy.isServer(entityplayer.world)) {
        return;
    }
    StringBuilder sb = new StringBuilder();
    ServerRouter router = (ServerRouter) getRouter();
    sb.append("***\n");
    sb.append("---------Interests---------------\n");
    ServerRouter.forEachGlobalSpecificInterest((itemIdentifier, serverRouters) -> {
        sb.append(itemIdentifier.getFriendlyName()).append(":");
        for (IRouter j : serverRouters) {
            sb.append(j.getSimpleID()).append(",");
        }
        sb.append('\n');
    });
    sb.append("ALL ITEMS:");
    for (IRouter j : ServerRouter.getInterestedInGeneral()) {
        sb.append(j.getSimpleID()).append(",");
    }
    sb.append('\n');
    sb.append(router).append('\n');
    sb.append("---------CONNECTED TO---------------\n");
    for (CoreRoutedPipe adj : router._adjacent.keySet()) {
        sb.append(adj.getRouter().getSimpleID()).append('\n');
    }
    sb.append('\n');
    sb.append("========DISTANCE TABLE==============\n");
    for (ExitRoute n : router.getIRoutersByCost()) {
        sb.append(n.destination.getSimpleID()).append(" @ ").append(n.distanceToDestination).append(" -> ").append(n.connectionDetails).append("(").append(n.destination.getId()).append(")").append('\n');
    }
    sb.append('\n');
    sb.append("*******EXIT ROUTE TABLE*************\n");
    List<List<ExitRoute>> table = router.getRouteTable();
    for (int i = 0; i < table.size(); i++) {
        if (table.get(i) != null) {
            if (table.get(i).size() > 0) {
                sb.append(i).append(" -> ").append(table.get(i).get(0).destination.getSimpleID()).append('\n');
                for (ExitRoute route : table.get(i)) {
                    sb.append("\t\t via ").append(route.exitOrientation).append("(").append(route.distanceToDestination).append(" distance)").append('\n');
                }
            }
        }
    }
    sb.append('\n');
    sb.append("++++++++++CONNECTIONS+++++++++++++++\n");
    sb.append(Arrays.toString(EnumFacing.VALUES)).append('\n');
    sb.append(Arrays.toString(router.sideDisconnected)).append('\n');
    if (container != null) {
        sb.append(Arrays.toString(container.pipeConnectionsBuffer)).append('\n');
    }
    sb.append("+++++++++++++ADJACENT+++++++++++++++\n");
    sb.append(adjacent).append('\n');
    sb.append("pointing: ").append(getPointedOrientation()).append('\n');
    sb.append("~~~~~~~~~~~~~~~POWER~~~~~~~~~~~~~~~~\n");
    sb.append(router.getPowerProvider()).append('\n');
    sb.append("~~~~~~~~~~~SUBSYSTEMPOWER~~~~~~~~~~~\n");
    sb.append(router.getSubSystemPowerProvider()).append('\n');
    if (_orderItemManager != null) {
        sb.append("################ORDERDUMP#################\n");
        _orderItemManager.dump(sb);
    }
    sb.append("################END#################\n");
    refreshConnectionAndRender(true);
    System.out.print(sb);
    router.CreateRouteTable(Integer.MAX_VALUE);
}
Also used : IRouter(logisticspipes.routing.IRouter) ArrayList(java.util.ArrayList) PlayerCollectionList(logisticspipes.utils.PlayerCollectionList) NBTTagList(net.minecraft.nbt.NBTTagList) List(java.util.List) LinkedList(java.util.LinkedList) ServerRouter(logisticspipes.routing.ServerRouter) ExitRoute(logisticspipes.routing.ExitRoute)

Aggregations

IRouter (logisticspipes.routing.IRouter)32 ExitRoute (logisticspipes.routing.ExitRoute)19 CoreRoutedPipe (logisticspipes.pipes.basic.CoreRoutedPipe)16 ArrayList (java.util.ArrayList)15 LinkedList (java.util.LinkedList)13 List (java.util.List)12 IFilter (logisticspipes.interfaces.routing.IFilter)10 PipeRoutingConnectionType (logisticspipes.routing.PipeRoutingConnectionType)8 Pair (logisticspipes.utils.tuples.Pair)7 ItemStack (net.minecraft.item.ItemStack)7 BitSet (java.util.BitSet)6 HashMap (java.util.HashMap)6 SimpleServiceLocator (logisticspipes.proxy.SimpleServiceLocator)6 Map (java.util.Map)5 ItemIdentifier (logisticspipes.utils.item.ItemIdentifier)5 ItemIdentifierStack (logisticspipes.utils.item.ItemIdentifierStack)5 EnumFacing (net.minecraft.util.EnumFacing)5 LogisticsTileGenericPipe (logisticspipes.pipes.basic.LogisticsTileGenericPipe)4 IResource (logisticspipes.request.resources.IResource)4 LaserData (logisticspipes.routing.LaserData)4