commit
aae0a98842
8 changed files with 67 additions and 24 deletions
|
@ -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<BlockIndex, Node> openList = new HashMap<BlockIndex, PathFinding.Node>();
|
||||
private HashMap<BlockIndex, Node> closedList = new HashMap<BlockIndex, PathFinding.Node>();
|
||||
|
@ -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)) {
|
||||
|
|
|
@ -32,6 +32,7 @@ public class PathFindingSearch implements IIterableAlgorithm {
|
|||
private List<PathFinding> 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<PathFinding>();
|
||||
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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -66,11 +66,6 @@ public class AIRobotPumpBlock extends AIRobot {
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void end() {
|
||||
robot.aimItemAt(0, 1, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnergyCost() {
|
||||
return 20;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue