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);
}
}
}));
}
}
}
}
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";
}
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;
}
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();
}
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);
}
Aggregations