Search in sources :

Example 6 with AIRobotGotoSleep

use of buildcraft.robotics.ai.AIRobotGotoSleep 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

AIRobotGotoSleep (buildcraft.robotics.ai.AIRobotGotoSleep)6 AIRobotSearchAndGotoBlock (buildcraft.robotics.ai.AIRobotSearchAndGotoBlock)4 AIRobotFetchAndEquipItemStack (buildcraft.robotics.ai.AIRobotFetchAndEquipItemStack)3 AIRobotGotoStationAndLoad (buildcraft.robotics.ai.AIRobotGotoStationAndLoad)2 ArrayStackFilter (buildcraft.lib.inventory.filter.ArrayStackFilter)1 AIRobotDeliverRequested (buildcraft.robotics.ai.AIRobotDeliverRequested)1 AIRobotDisposeItems (buildcraft.robotics.ai.AIRobotDisposeItems)1 AIRobotGotoBlock (buildcraft.robotics.ai.AIRobotGotoBlock)1 AIRobotGotoStationAndUnloadFluids (buildcraft.robotics.ai.AIRobotGotoStationAndUnloadFluids)1 AIRobotPlant (buildcraft.robotics.ai.AIRobotPlant)1 AIRobotPumpBlock (buildcraft.robotics.ai.AIRobotPumpBlock)1 AIRobotRecharge (buildcraft.robotics.ai.AIRobotRecharge)1 AIRobotSearchStackRequest (buildcraft.robotics.ai.AIRobotSearchStackRequest)1 AIRobotStripesHandler (buildcraft.robotics.ai.AIRobotStripesHandler)1 AIRobotUseToolOnBlock (buildcraft.robotics.ai.AIRobotUseToolOnBlock)1