use of logisticspipes.routing.ExitRoute in project LogisticsPipes by RS485.
the class ModuleCrafter method getNextConnectFluidSatelliteId.
protected int getNextConnectFluidSatelliteId(boolean prev, int x) {
int closestIdFound = prev ? 0 : Integer.MAX_VALUE;
for (final PipeFluidSatellite satellite : PipeFluidSatellite.AllSatellites) {
CoreRoutedPipe satPipe = satellite;
if (satPipe == null || satPipe.stillNeedReplace() || satPipe.getRouter() == null || !satPipe.isFluidPipe()) {
continue;
}
IRouter satRouter = satPipe.getRouter();
List<ExitRoute> routes = getRouter().getDistanceTo(satRouter);
if (routes != null && !routes.isEmpty()) {
boolean filterFree = false;
for (ExitRoute route : routes) {
if (route.filters.isEmpty()) {
filterFree = true;
break;
}
}
if (!filterFree) {
continue;
}
if (x == -1) {
if (!prev && satellite.satelliteId > liquidSatelliteId && satellite.satelliteId < closestIdFound) {
closestIdFound = satellite.satelliteId;
} else if (prev && satellite.satelliteId < liquidSatelliteId && satellite.satelliteId > closestIdFound) {
closestIdFound = satellite.satelliteId;
}
} else {
if (!prev && satellite.satelliteId > liquidSatelliteIdArray[x] && satellite.satelliteId < closestIdFound) {
closestIdFound = satellite.satelliteId;
} else if (prev && satellite.satelliteId < liquidSatelliteIdArray[x] && satellite.satelliteId > closestIdFound) {
closestIdFound = satellite.satelliteId;
}
}
}
}
if (closestIdFound == Integer.MAX_VALUE) {
if (x == -1) {
return liquidSatelliteId;
} else {
return liquidSatelliteIdArray[x];
}
}
return closestIdFound;
}
use of logisticspipes.routing.ExitRoute in project LogisticsPipes by RS485.
the class RequestRunningCraftingTasks method processPacket.
@Override
public void processPacket(EntityPlayer player) {
LogisticsStatisticsTileEntity tile = this.getTile(player.getEntityWorld(), LogisticsStatisticsTileEntity.class);
CoreRoutedPipe pipe = tile.getConnectedPipe();
if (pipe == null) {
return;
}
List<ItemIdentifierStack> items = new ArrayList<>();
for (ExitRoute r : pipe.getRouter().getIRoutersByCost()) {
if (r == null) {
continue;
}
if (r.destination.getPipe() instanceof PipeItemsCraftingLogistics) {
PipeItemsCraftingLogistics crafting = (PipeItemsCraftingLogistics) r.destination.getPipe();
List<ItemIdentifierStack> content = crafting.getItemOrderManager().getContentList(player.getEntityWorld());
items.addAll(content);
}
}
MainProxy.sendPacketToPlayer(PacketHandler.getPacket(RunningCraftingTasks.class).setIdentList(items), player);
}
use of logisticspipes.routing.ExitRoute in project LogisticsPipes by RS485.
the class RequestRoutingLasersPacket method handleRouteInDirection.
private void handleRouteInDirection(final LogisticsTileGenericPipe pipeIn, ForgeDirection 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 ForgeDirection 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 (LPConstants.DEBUG) {
log.log("Size: " + connectedRouters.size());
}
lasers.add(new LaserData(pipe.xCoord, pipe.yCoord, pipe.zCoord, dir, connectionType).setStartPipe(firstPipe));
firstPipe = false;
HashMap<CoreRoutedPipe, ExitRoute> map = PathFinder.paintAndgetConnectedRoutingPipes(pipe, dir, Configs.LOGISTICS_DETECTION_COUNT, Configs.LOGISTICS_DETECTION_LENGTH, (worldObj, laser) -> {
if (pipe.getWorld() == worldObj) {
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<ForgeDirection, 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 ForgeDirection exitDir : routers.keySet()) {
if (exitDir == ForgeDirection.UNKNOWN) {
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 (LPConstants.DEBUG) {
log.log(exitDir.name() + ": " + logString);
}
}
}));
}
}
}
}
use of logisticspipes.routing.ExitRoute in project LogisticsPipes by RS485.
the class CoreRoutedPipe method doDebugStuff.
private void doDebugStuff(EntityPlayer entityplayer) {
//entityplayer.worldObj.setWorldTime(4951);
IRouter r = getRouter();
if (!(r instanceof ServerRouter)) {
return;
}
System.out.println("***");
System.out.println("---------Interests---------------");
for (Entry<ItemIdentifier, Set<IRouter>> i : ServerRouter.getInterestedInSpecifics().entrySet()) {
System.out.print(i.getKey().getFriendlyName() + ":");
for (IRouter j : i.getValue()) {
System.out.print(j.getSimpleID() + ",");
}
System.out.println();
}
System.out.print("ALL ITEMS:");
for (IRouter j : ServerRouter.getInterestedInGeneral()) {
System.out.print(j.getSimpleID() + ",");
}
System.out.println();
ServerRouter sr = (ServerRouter) r;
System.out.println(r.toString());
System.out.println("---------CONNECTED TO---------------");
for (CoreRoutedPipe adj : sr._adjacent.keySet()) {
System.out.println(adj.getRouter().getSimpleID());
}
System.out.println();
System.out.println("========DISTANCE TABLE==============");
for (ExitRoute n : r.getIRoutersByCost()) {
System.out.println(n.destination.getSimpleID() + " @ " + n.distanceToDestination + " -> " + n.connectionDetails + "(" + n.destination.getId() + ")");
}
System.out.println();
System.out.println("*******EXIT ROUTE TABLE*************");
List<List<ExitRoute>> table = r.getRouteTable();
for (int i = 0; i < table.size(); i++) {
if (table.get(i) != null) {
if (table.get(i).size() > 0) {
System.out.println(i + " -> " + table.get(i).get(0).destination.getSimpleID());
for (ExitRoute route : table.get(i)) {
System.out.println("\t\t via " + route.exitOrientation + "(" + route.distanceToDestination + " distance)");
}
}
}
}
System.out.println();
System.out.println("++++++++++CONNECTIONS+++++++++++++++");
System.out.println(Arrays.toString(ForgeDirection.VALID_DIRECTIONS));
System.out.println(Arrays.toString(sr.sideDisconnected));
System.out.println(Arrays.toString(container.pipeConnectionsBuffer));
System.out.println();
System.out.println("~~~~~~~~~~~~~~~POWER~~~~~~~~~~~~~~~~");
System.out.println(r.getPowerProvider());
System.out.println();
System.out.println("~~~~~~~~~~~SUBSYSTEMPOWER~~~~~~~~~~~");
System.out.println(r.getSubSystemPowerProvider());
System.out.println();
if (_orderItemManager != null) {
System.out.println("################ORDERDUMP#################");
_orderItemManager.dump();
}
System.out.println("################END#################");
refreshConnectionAndRender(true);
System.out.print("");
sr.CreateRouteTable(Integer.MAX_VALUE);
}
use of logisticspipes.routing.ExitRoute in project LogisticsPipes by RS485.
the class LogisticsRoutingBoardRobot method findTarget.
private Pair<Double, LogisticsRoutingBoardRobot> findTarget() {
Pair<Double, LogisticsRoutingBoardRobot> result = null;
DoubleCoordinates robotPos = new DoubleCoordinates(robot);
for (Pair<DoubleCoordinates, ForgeDirection> canidatePos : connectionDetails.localConnectedRobots) {
if (robot.getLinkedStation() == null) {
continue;
}
if (canidatePos.getValue1().equals(new DoubleCoordinates(robot.getLinkedStation().x(), robot.getLinkedStation().y(), robot.getLinkedStation().z()))) {
continue;
}
double distance = CoordinateUtils.add(new DoubleCoordinates(canidatePos.getValue1()).center(), canidatePos.getValue2(), 0.5).distanceTo(robotPos);
if (result == null || result.getValue1() > distance) {
TileEntity connectedPipeTile = canidatePos.getValue1().getTileEntity(robot.worldObj);
if (!(connectedPipeTile instanceof LogisticsTileGenericPipe)) {
continue;
}
LogisticsTileGenericPipe connectedPipe = (LogisticsTileGenericPipe) connectedPipeTile;
if (!connectedPipe.isRoutingPipe()) {
continue;
}
PipePluggable connectedPluggable = ((TileGenericPipe) connectedPipe.tilePart.getOriginal()).getPipePluggable(canidatePos.getValue2());
if (!(connectedPluggable instanceof RobotStationPluggable)) {
continue;
}
DockingStation connectedStation = ((RobotStationPluggable) connectedPluggable).getStation();
if (!connectedStation.isTaken()) {
continue;
}
EntityRobotBase connectedRobot = connectedStation.robotTaking();
if (connectedRobot == null) {
continue;
}
if (!(connectedRobot.getBoard() instanceof LogisticsRoutingBoardRobot)) {
continue;
}
if (connectedRobot.isDead) {
continue;
}
if (connectedRobot.getZoneToWork() != null && !connectedRobot.getZoneToWork().contains(robotPos.getXCoord(), robotPos.getYCoord(), robotPos.getZCoord())) {
continue;
}
if (!((LogisticsRoutingBoardRobot) connectedRobot.getBoard()).isAcceptsItems()) {
continue;
}
if (((LogisticsRoutingBoardRobot) connectedRobot.getBoard()).getCurrentTarget() != null && ((LogisticsRoutingBoardRobot) connectedRobot.getBoard()).getCurrentTarget().getValue2() != robot.getBoard()) {
continue;
}
DoubleCoordinates connectedRobotPos = new DoubleCoordinates(connectedRobot);
if (CoordinateUtils.add(new DoubleCoordinates(canidatePos.getValue1()).center(), canidatePos.getValue2(), 0.5).distanceTo(connectedRobotPos) > 0.05) {
// Not at station
continue;
}
Double mindis = Double.NaN;
for (LPTravelingItemServer item : items) {
item.checkIDFromUUID();
if (item.getInfo().destinationint < 0) {
continue;
}
ExitRoute route = connectedPipe.getRoutingPipe().getRouter().getExitFor(item.getInfo().destinationint, item.getInfo()._transportMode == TransportMode.Active, item.getItemIdentifierStack().getItem());
if (route == null) {
continue;
}
if (mindis.isNaN()) {
mindis = route.distanceToDestination;
}
mindis = Math.min(mindis, route.distanceToDestination);
}
if (mindis.isNaN()) {
continue;
}
double distanceToItem = ((distance * 3) + 21) + mindis;
if (result == null || result.getValue1() > distanceToItem) {
result = new Pair<>(distanceToItem, (LogisticsRoutingBoardRobot) connectedRobot.getBoard());
}
}
}
return result;
}
Aggregations