Search in sources :

Example 1 with IPipeInformationProvider

use of logisticspipes.routing.pathfinder.IPipeInformationProvider in project LogisticsPipes by RS485.

the class CoreUnroutedPipe method getDistanceTo.

public double getDistanceTo(int destinationint, ForgeDirection ignore, ItemIdentifier ident, boolean isActive, double travled, double max, List<DoubleCoordinates> visited) {
    double lowest = Integer.MAX_VALUE;
    for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
        if (ignore == dir) {
            continue;
        }
        IPipeInformationProvider information = SimpleServiceLocator.pipeInformationManager.getInformationProviderFor(container.getNextConnectedTile(dir));
        if (information != null) {
            DoubleCoordinates pos = new DoubleCoordinates(information);
            if (visited.contains(pos)) {
                continue;
            }
            visited.add(pos);
            lowest = information.getDistanceTo(destinationint, dir.getOpposite(), ident, isActive, travled, Math.min(max, lowest), visited);
            visited.remove(pos);
        }
    }
    return lowest;
}
Also used : IPipeInformationProvider(logisticspipes.routing.pathfinder.IPipeInformationProvider) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates)

Example 2 with IPipeInformationProvider

use of logisticspipes.routing.pathfinder.IPipeInformationProvider in project LogisticsPipes by RS485.

the class BCPipeInformationProvider method getDistanceTo.

@Override
public double getDistanceTo(int destinationint, ForgeDirection ignore, ItemIdentifier ident, boolean isActive, double traveled, double max, List<DoubleCoordinates> visited) {
    if (traveled >= max) {
        return Integer.MAX_VALUE;
    }
    for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
        if (ignore == dir) {
            continue;
        }
        IPipeInformationProvider information = SimpleServiceLocator.pipeInformationManager.getInformationProviderFor(getNextConnectedTile(dir));
        if (information != null) {
            DoubleCoordinates pos = new DoubleCoordinates(information);
            if (visited.contains(pos)) {
                continue;
            }
            visited.add(pos);
            double result = information.getDistanceTo(destinationint, dir.getOpposite(), ident, isActive, traveled + getDistance(), max, visited);
            visited.remove(pos);
            if (result == Integer.MAX_VALUE) {
                return result;
            }
            return result + (int) getDistance();
        }
    }
    return Integer.MAX_VALUE;
}
Also used : IPipeInformationProvider(logisticspipes.routing.pathfinder.IPipeInformationProvider) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates)

Example 3 with IPipeInformationProvider

use of logisticspipes.routing.pathfinder.IPipeInformationProvider in project LogisticsPipes by RS485.

the class BCPipeInformationProvider method getDistanceTo.

@Override
public double getDistanceTo(int destinationint, EnumFacing ignore, ItemIdentifier ident, boolean isActive, double traveled, double max, List<DoubleCoordinates> visited) {
    if (traveled >= max) {
        return Integer.MAX_VALUE;
    }
    for (EnumFacing dir : EnumFacing.VALUES) {
        if (ignore == dir) {
            continue;
        }
        IPipeInformationProvider information = SimpleServiceLocator.pipeInformationManager.getInformationProviderFor(getNextConnectedTile(dir));
        if (information != null) {
            DoubleCoordinates pos = new DoubleCoordinates(information);
            if (visited.contains(pos)) {
                continue;
            }
            visited.add(pos);
            double result = information.getDistanceTo(destinationint, dir.getOpposite(), ident, isActive, traveled + getDistance(), max, visited);
            visited.remove(pos);
            if (result == Integer.MAX_VALUE) {
                return result;
            }
            return result + (int) getDistance();
        }
    }
    return Integer.MAX_VALUE;
}
Also used : IPipeInformationProvider(logisticspipes.routing.pathfinder.IPipeInformationProvider) EnumFacing(net.minecraft.util.EnumFacing) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates)

Example 4 with IPipeInformationProvider

use of logisticspipes.routing.pathfinder.IPipeInformationProvider in project LogisticsPipes by RS485.

the class MainProxy method checkPipesConnections.

public static boolean checkPipesConnections(TileEntity from, TileEntity to, ForgeDirection way, boolean ignoreSystemDisconnection) {
    if (from == null || to == null) {
        return false;
    }
    IPipeInformationProvider fromInfo = SimpleServiceLocator.pipeInformationManager.getInformationProviderFor(from);
    IPipeInformationProvider toInfo = SimpleServiceLocator.pipeInformationManager.getInformationProviderFor(to);
    if (fromInfo == null && toInfo == null) {
        return false;
    }
    if (fromInfo != null) {
        if (!fromInfo.canConnect(to, way, ignoreSystemDisconnection)) {
            return false;
        }
    }
    if (toInfo != null) {
        if (!toInfo.canConnect(from, way.getOpposite(), ignoreSystemDisconnection)) {
            return false;
        }
    }
    return true;
}
Also used : IPipeInformationProvider(logisticspipes.routing.pathfinder.IPipeInformationProvider)

Example 5 with IPipeInformationProvider

use of logisticspipes.routing.pathfinder.IPipeInformationProvider in project LogisticsPipes by RS485.

the class LPRobotConnectionControl method getConnections.

@Override
public List<ConnectionInformation> getConnections(IPipeInformationProvider startPipe, EnumSet<PipeRoutingConnectionType> connection, ForgeDirection side) {
    List<ConnectionInformation> list = new ArrayList<>();
    LogisticsTileGenericPipe pipe = (LogisticsTileGenericPipe) startPipe;
    if (pipe == null || pipe.tilePart.getOriginal() == null) {
        // Proxy got disabled
        return list;
    }
    DoubleCoordinates pos = new DoubleCoordinates(startPipe);
    pos.center();
    for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
        PipePluggable pluggable = ((TileGenericPipe) pipe.tilePart.getOriginal()).getPipePluggable(dir);
        if (!(pluggable instanceof RobotStationPluggable)) {
            continue;
        }
        DockingStation station = ((RobotStationPluggable) pluggable).getStation();
        if (!station.isTaken()) {
            continue;
        }
        EntityRobotBase robot = station.robotTaking();
        if (robot == null) {
            continue;
        }
        if (!(robot.getBoard() instanceof LogisticsRoutingBoardRobot)) {
            continue;
        }
        if (robot.isDead) {
            continue;
        }
        if (!((LogisticsRoutingBoardRobot) robot.getBoard()).isAcceptsItems()) {
            continue;
        }
        DoubleCoordinates robotPos = new DoubleCoordinates(robot);
        if (((LogisticsRoutingBoardRobot) robot.getBoard()).getCurrentTarget() != null) {
            Pair<Double, LogisticsRoutingBoardRobot> currentTarget = ((LogisticsRoutingBoardRobot) robot.getBoard()).getCurrentTarget();
            DoubleCoordinates pipePos = currentTarget.getValue2().getLinkedStationPosition();
            TileEntity connectedPipeTile = pipePos.getTileEntity(pipe.getWorldObj());
            if (!(connectedPipeTile instanceof LogisticsTileGenericPipe)) {
                continue;
            }
            LogisticsTileGenericPipe connectedPipe = (LogisticsTileGenericPipe) connectedPipeTile;
            if (!connectedPipe.isRoutingPipe()) {
                continue;
            }
            IPipeInformationProvider connectedInfo = SimpleServiceLocator.pipeInformationManager.getInformationProviderFor(connectedPipe);
            EntityRobotBase connectedRobot = currentTarget.getValue2().robot;
            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;
            }
            DoubleCoordinates connectedRobotPos = new DoubleCoordinates(connectedRobot);
            if (CoordinateUtils.add(new DoubleCoordinates(pipePos).center(), currentTarget.getValue2().robot.getLinkedStation().side(), 0.5).distanceTo(connectedRobotPos) > 0.05) {
                // Not at station
                continue;
            }
            EnumSet<PipeRoutingConnectionType> newCon = connection.clone();
            newCon.removeAll(EnumSet.of(PipeRoutingConnectionType.canPowerFrom, PipeRoutingConnectionType.canPowerSubSystemFrom));
            double distance = CoordinateUtils.add(new DoubleCoordinates(currentTarget.getValue2().getLinkedStationPosition()).center(), currentTarget.getValue2().robot.getLinkedStation().side(), 0.5).distanceTo(robotPos);
            list.add(new ConnectionInformation(connectedInfo, newCon, currentTarget.getValue2().robot.getLinkedStation().side().getOpposite(), dir, (distance * 3) + 21));
        } else {
            if (CoordinateUtils.add(new DoubleCoordinates(pos), dir, 0.5).distanceTo(robotPos) > 0.05) {
                // Not at station
                continue;
            }
            for (Pair<DoubleCoordinates, ForgeDirection> canidatePos : ((LogisticsRoutingBoardRobot) robot.getBoard()).getConnectionDetails().localConnectedRobots) {
                if (canidatePos.getValue1().equals(new DoubleCoordinates(startPipe))) {
                    continue;
                }
                double distance = CoordinateUtils.add(new DoubleCoordinates(canidatePos.getValue1()).center(), canidatePos.getValue2(), 0.5).distanceTo(robotPos);
                TileEntity connectedPipeTile = canidatePos.getValue1().getTileEntity(pipe.getWorldObj());
                if (!(connectedPipeTile instanceof LogisticsTileGenericPipe)) {
                    continue;
                }
                LogisticsTileGenericPipe connectedPipe = (LogisticsTileGenericPipe) connectedPipeTile;
                if (!connectedPipe.isRoutingPipe()) {
                    continue;
                }
                IPipeInformationProvider connectedInfo = SimpleServiceLocator.pipeInformationManager.getInformationProviderFor(connectedPipe);
                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;
                }
                EnumSet<PipeRoutingConnectionType> newCon = connection.clone();
                newCon.removeAll(EnumSet.of(PipeRoutingConnectionType.canPowerFrom, PipeRoutingConnectionType.canPowerSubSystemFrom));
                list.add(new ConnectionInformation(connectedInfo, newCon, canidatePos.getValue2().getOpposite(), dir, (distance * 3) + 21));
            }
        }
    }
    return list;
}
Also used : ConnectionInformation(logisticspipes.proxy.specialconnection.SpecialPipeConnection.ConnectionInformation) RobotStationPluggable(buildcraft.robotics.RobotStationPluggable) DockingStation(buildcraft.api.robots.DockingStation) PipeRoutingConnectionType(logisticspipes.routing.PipeRoutingConnectionType) LogisticsRoutingBoardRobot(logisticspipes.proxy.buildcraft.robots.boards.LogisticsRoutingBoardRobot) ArrayList(java.util.ArrayList) PipePluggable(buildcraft.api.transport.pluggable.PipePluggable) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates) TileEntity(net.minecraft.tileentity.TileEntity) IPipeInformationProvider(logisticspipes.routing.pathfinder.IPipeInformationProvider) LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe) TileGenericPipe(buildcraft.transport.TileGenericPipe) LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) EntityRobotBase(buildcraft.api.robots.EntityRobotBase)

Aggregations

IPipeInformationProvider (logisticspipes.routing.pathfinder.IPipeInformationProvider)8 DoubleCoordinates (network.rs485.logisticspipes.world.DoubleCoordinates)5 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)3 EnumFacing (net.minecraft.util.EnumFacing)2 DockingStation (buildcraft.api.robots.DockingStation)1 EntityRobotBase (buildcraft.api.robots.EntityRobotBase)1 PipePluggable (buildcraft.api.transport.pluggable.PipePluggable)1 RobotStationPluggable (buildcraft.robotics.RobotStationPluggable)1 TileGenericPipe (buildcraft.transport.TileGenericPipe)1 ArrayList (java.util.ArrayList)1 LogisticsTileGenericPipe (logisticspipes.pipes.basic.LogisticsTileGenericPipe)1 LogisticsRoutingBoardRobot (logisticspipes.proxy.buildcraft.robots.boards.LogisticsRoutingBoardRobot)1 ConnectionInformation (logisticspipes.proxy.specialconnection.SpecialPipeConnection.ConnectionInformation)1 PipeRoutingConnectionType (logisticspipes.routing.PipeRoutingConnectionType)1 TileEntity (net.minecraft.tileentity.TileEntity)1