Search in sources :

Example 1 with AIRobotDisposeItems

use of buildcraft.robotics.ai.AIRobotDisposeItems in project BuildCraft by BuildCraft.

the class BoardRobotBuilder method update.

@Override
public void update() {
    if (launchingDelay > 0) {
        launchingDelay--;
        return;
    }
    if (markerToBuild == null) {
        markerToBuild = findClosestMarker();
        if (markerToBuild == null) {
            if (robot.containsItems()) {
                startDelegateAI(new AIRobotDisposeItems(robot));
            } else {
                startDelegateAI(new AIRobotGotoSleep(robot));
            }
            return;
        }
    }
    if (!markerToBuild.needsToBuild()) {
        markerToBuild = null;
        currentBuildingSlot = null;
        return;
    }
    if (currentBuildingSlot == null) {
        currentBuildingSlot = markerToBuild.bluePrintBuilder.reserveNextSlot(robot.worldObj);
        if (currentBuildingSlot == null) {
            // No slots available yet
            launchingDelay = 40;
            return;
        }
    }
    if (requirementsToLookFor == null) {
        if (robot.containsItems()) {
            startDelegateAI(new AIRobotDisposeItems(robot));
        }
        if (robot.worldObj.getWorldInfo().getGameType() != WorldSettings.GameType.CREATIVE) {
            requirementsToLookFor = currentBuildingSlot.getRequirements(markerToBuild.getContext());
        } else {
            requirementsToLookFor = new LinkedList<>();
        }
        if (requirementsToLookFor == null) {
            launchingDelay = 40;
            return;
        }
        if (requirementsToLookFor.size() > 4) {
            currentBuildingSlot.built = true;
            currentBuildingSlot = null;
            requirementsToLookFor = null;
            return;
        }
    }
    if (requirementsToLookFor.size() > 0) {
        startDelegateAI(new AIRobotGotoStationAndLoad(robot, new ArrayStackFilter(requirementsToLookFor.get(0)), requirementsToLookFor.get(0).stackSize));
        return;
    }
    if (requirementsToLookFor.size() == 0) {
        if (currentBuildingSlot.stackConsumed == null) {
            // Once all the element are in, if not already, use them to
            // prepare the slot.
            markerToBuild.bluePrintBuilder.useRequirements(robot, currentBuildingSlot);
        }
        if (!hasEnoughEnergy()) {
            startDelegateAI(new AIRobotRecharge(robot));
        } else {
            startDelegateAI(new AIRobotGotoBlock(robot, Utils.convertFloor(currentBuildingSlot.getDestination()), 8));
        }
    // TODO: take into account cases where the robot can't reach the
    // destination - go to work on another block
    }
}
Also used : ArrayStackFilter(buildcraft.lib.inventory.filter.ArrayStackFilter) AIRobotGotoStationAndLoad(buildcraft.robotics.ai.AIRobotGotoStationAndLoad) AIRobotGotoSleep(buildcraft.robotics.ai.AIRobotGotoSleep) AIRobotDisposeItems(buildcraft.robotics.ai.AIRobotDisposeItems) AIRobotGotoBlock(buildcraft.robotics.ai.AIRobotGotoBlock) AIRobotRecharge(buildcraft.robotics.ai.AIRobotRecharge)

Aggregations

ArrayStackFilter (buildcraft.lib.inventory.filter.ArrayStackFilter)1 AIRobotDisposeItems (buildcraft.robotics.ai.AIRobotDisposeItems)1 AIRobotGotoBlock (buildcraft.robotics.ai.AIRobotGotoBlock)1 AIRobotGotoSleep (buildcraft.robotics.ai.AIRobotGotoSleep)1 AIRobotGotoStationAndLoad (buildcraft.robotics.ai.AIRobotGotoStationAndLoad)1 AIRobotRecharge (buildcraft.robotics.ai.AIRobotRecharge)1