diff --git a/common/buildcraft/core/utils/concurrency/PathFinding.java b/common/buildcraft/core/utils/concurrency/PathFinding.java index 427414c7..76e78b82 100755 --- a/common/buildcraft/core/utils/concurrency/PathFinding.java +++ b/common/buildcraft/core/utils/concurrency/PathFinding.java @@ -34,6 +34,7 @@ public class PathFinding implements IIterableAlgorithm { private IBlockFilter pathFound; private IZone zone; private double maxDistanceToEnd = 0; + private float maxTotalDistance = 0; private HashMap openList = new HashMap(); private HashMap closedList = new HashMap(); @@ -65,6 +66,13 @@ public class PathFinding implements IIterableAlgorithm { maxDistanceToEnd = iMaxDistanceToEnd; } + public PathFinding(World iWorld, BlockIndex iStart, BlockIndex iEnd, double iMaxDistanceToEnd, + float iMaxTotalDistance) { + this(iWorld, iStart, iEnd, iMaxDistanceToEnd); + + maxTotalDistance = iMaxTotalDistance; + } + @Override public void iterate() { iterate(PATH_ITERATIONS); @@ -147,6 +155,12 @@ public class PathFinding implements IIterableAlgorithm { nextNode.totalWeight = nextNode.movementCost + nextNode.destinationCost; + if (maxTotalDistance > 0 && nextNode.totalWeight > maxTotalDistance) { + if (!closedList.containsKey(nextNode.index)) { + closedList.put(nextNode.index, nextNode); + } + continue; + } if (closedList.containsKey(nextNode.index)) { continue; } else if (openList.containsKey(nextNode.index)) { diff --git a/common/buildcraft/core/utils/concurrency/PathFindingSearch.java b/common/buildcraft/core/utils/concurrency/PathFindingSearch.java index 340d8236..f4b0626d 100644 --- a/common/buildcraft/core/utils/concurrency/PathFindingSearch.java +++ b/common/buildcraft/core/utils/concurrency/PathFindingSearch.java @@ -32,6 +32,7 @@ public class PathFindingSearch implements IIterableAlgorithm { private List pathFinders; private IBlockFilter pathFound; private IZone zone; + private float maxDistance; private int searchRadius; private int searchX; @@ -39,11 +40,14 @@ public class PathFindingSearch implements IIterableAlgorithm { private int searchZ; private int searchHeight; + public PathFindingSearch(World iWorld, BlockIndex iStart, IBlockFilter iPathFound, float iMaxDistance, IZone iZone) { world = iWorld; start = iStart; pathFound = iPathFound; + maxDistance = iMaxDistance; + pathFinders = new LinkedList(); searchRadius = 1; searchX = -1; @@ -67,32 +71,51 @@ public class PathFindingSearch implements IIterableAlgorithm { int currZ = start.z + searchZ; if (0 <= currY && currY <= searchHeight) { if (isTarget(currX, currY, currZ)) { - pathFinders.add(new PathFinding(world, start, new BlockIndex(currX, currY, currZ))); + pathFinders.add(new PathFinding(world, start, new BlockIndex(currX, currY, currZ), 0, maxDistance)); } } - searchY += 1; - if (searchY > searchRadius) { - searchY = -searchRadius; - searchZ += 1; - if (searchZ > searchRadius) { - searchZ = -searchRadius; - searchX += 1; - if (searchX > searchRadius) { - searchRadius += 1; - searchX = -searchRadius; - searchY = -searchRadius; - searchZ = -searchRadius; - } - } - searchHeight = getSearchHeight(start.x + searchX, start.z + searchZ); - } + nextSearchStep(); + if (pathFinders.size() >= 5) { return; } } } + private void nextSearchStep() { + // Step through each block in a hollow cube of size (searchRadius * 2 -1), if done + // add 1 to the radius and start over. + + // Step to the next Y + if (Math.abs(searchX) == searchRadius || Math.abs(searchZ) == searchRadius) { + searchY += 1; + } else { + searchY += searchRadius * 2; + } + + if (searchY > searchRadius) { + // Step to the next Z + searchY = -searchRadius; + searchZ += 1; + + if (searchZ > searchRadius) { + // Step to the next X + searchZ = -searchRadius; + searchX += 1; + + if (searchX > searchRadius) { + // Step to the next radius + searchRadius += 1; + searchX = -searchRadius; + searchY = -searchRadius; + searchZ = -searchRadius; + } + } + searchHeight = getSearchHeight(start.x + searchX, start.z + searchZ); + } + } + private boolean isTarget(int x, int y, int z) { if (zone != null && !zone.contains(x, y, z)) { return false; diff --git a/common/buildcraft/robots/EntityRobot.java b/common/buildcraft/robots/EntityRobot.java index 426144d9..a8411579 100644 --- a/common/buildcraft/robots/EntityRobot.java +++ b/common/buildcraft/robots/EntityRobot.java @@ -948,6 +948,14 @@ public class EntityRobot extends EntityRobotBase implements NBTUtils.getItemData(robotStack).setTag("board", originalBoardNBT); NBTUtils.getItemData(robotStack).setInteger("energy", battery.getEnergyStored()); entityDropItem(robotStack, 0); + if (itemInUse != null) { + entityDropItem(itemInUse, 0); + } + for (ItemStack element : inv) { + if (element != null) { + entityDropItem(element, 0); + } + } getRegistry().killRobot(this); } diff --git a/common/buildcraft/robots/EntityRobotEnergyParticle.java b/common/buildcraft/robots/EntityRobotEnergyParticle.java index 015d25b3..1ff71d7d 100755 --- a/common/buildcraft/robots/EntityRobotEnergyParticle.java +++ b/common/buildcraft/robots/EntityRobotEnergyParticle.java @@ -81,7 +81,7 @@ public class EntityRobotEnergyParticle extends EntityFX { if (this.posY == this.prevPosY) { this.motionX *= 1.1D; - this.motionY *= 1.1D; + this.motionY = 0.001D; this.motionZ *= 1.1D; } diff --git a/common/buildcraft/robots/ai/AIRobotGotoBlock.java b/common/buildcraft/robots/ai/AIRobotGotoBlock.java index cb043a35..67a5fdf7 100755 --- a/common/buildcraft/robots/ai/AIRobotGotoBlock.java +++ b/common/buildcraft/robots/ai/AIRobotGotoBlock.java @@ -41,6 +41,7 @@ public class AIRobotGotoBlock extends AIRobotGoto { finalX = x; finalY = y; finalZ = z; + robot.aimItemAt((int) Math.floor(finalX), (int) Math.floor(finalY), (int) Math.floor(finalZ)); } public AIRobotGotoBlock(EntityRobotBase robot, int x, int y, int z, double iMaxDistance) { @@ -55,6 +56,7 @@ public class AIRobotGotoBlock extends AIRobotGoto { finalX = path.getLast().x; finalY = path.getLast().y; finalZ = path.getLast().z; + robot.aimItemAt((int) Math.floor(finalX), (int) Math.floor(finalY), (int) Math.floor(finalZ)); setNextInPath(); } diff --git a/common/buildcraft/robots/ai/AIRobotPumpBlock.java b/common/buildcraft/robots/ai/AIRobotPumpBlock.java index 98d30685..7c541ac9 100644 --- a/common/buildcraft/robots/ai/AIRobotPumpBlock.java +++ b/common/buildcraft/robots/ai/AIRobotPumpBlock.java @@ -66,11 +66,6 @@ public class AIRobotPumpBlock extends AIRobot { } - @Override - public void end() { - robot.aimItemAt(0, 1, 0); - } - @Override public int getEnergyCost() { return 20; diff --git a/common/buildcraft/robots/ai/AIRobotSearchBlock.java b/common/buildcraft/robots/ai/AIRobotSearchBlock.java index 054a3d96..2a5c67cc 100755 --- a/common/buildcraft/robots/ai/AIRobotSearchBlock.java +++ b/common/buildcraft/robots/ai/AIRobotSearchBlock.java @@ -39,7 +39,7 @@ public class AIRobotSearchBlock extends AIRobot { @Override public void start() { - blockScanner = new PathFindingSearch(robot.worldObj, new BlockIndex(robot), pathFound, 64, robot.getZoneToWork()); + blockScanner = new PathFindingSearch(robot.worldObj, new BlockIndex(robot), pathFound, 96, robot.getZoneToWork()); blockScannerJob = new IterableAlgorithmRunner(blockScanner, 40000); blockScannerJob.start(); } diff --git a/common/buildcraft/robots/ai/AIRobotStraightMoveTo.java b/common/buildcraft/robots/ai/AIRobotStraightMoveTo.java index d08a2ca2..34e7c7d4 100755 --- a/common/buildcraft/robots/ai/AIRobotStraightMoveTo.java +++ b/common/buildcraft/robots/ai/AIRobotStraightMoveTo.java @@ -26,6 +26,7 @@ public class AIRobotStraightMoveTo extends AIRobotGoto { x = ix; y = iy; z = iz; + robot.aimItemAt((int) Math.floor(x), (int) Math.floor(y), (int) Math.floor(z)); } @Override