fix robots not respecting work zones, fixes #2677
This commit is contained in:
parent
84dd13cadc
commit
89160d017a
3 changed files with 7 additions and 33 deletions
|
@ -15,7 +15,6 @@ import java.util.LinkedList;
|
|||
import net.minecraft.world.World;
|
||||
import buildcraft.api.core.BlockIndex;
|
||||
import buildcraft.api.core.BuildCraftAPI;
|
||||
import buildcraft.api.core.IZone;
|
||||
|
||||
/**
|
||||
* This class implements a 3D path finding based on the A* algorithm, following
|
||||
|
@ -29,8 +28,6 @@ public class PathFinding implements IIterableAlgorithm {
|
|||
private World world;
|
||||
private BlockIndex start;
|
||||
private BlockIndex end;
|
||||
private IBlockFilter pathFound;
|
||||
private IZone zone;
|
||||
private double maxDistanceToEndSq = 0;
|
||||
private float maxTotalDistanceSq = 0;
|
||||
|
||||
|
@ -138,20 +135,7 @@ public class PathFinding implements IIterableAlgorithm {
|
|||
}
|
||||
|
||||
nextNode.movementCost = from.movementCost + distanceSq(nextNode.index, from.index);
|
||||
|
||||
if (end != null) {
|
||||
nextNode.destinationCost = distanceSq(nextNode.index, end);
|
||||
} else if (zone != null) {
|
||||
if (zone.contains(x, y, z)) {
|
||||
nextNode.destinationCost = 0;
|
||||
} else {
|
||||
nextNode.destinationCost = zone.distanceToSquared(nextNode.index);
|
||||
|
||||
}
|
||||
} else {
|
||||
nextNode.destinationCost = 0;
|
||||
}
|
||||
|
||||
nextNode.destinationCost = distanceSq(nextNode.index, end);
|
||||
nextNode.totalWeight = nextNode.movementCost + nextNode.destinationCost;
|
||||
|
||||
if (maxTotalDistanceSq > 0 && nextNode.totalWeight > maxTotalDistanceSq) {
|
||||
|
@ -206,10 +190,6 @@ public class PathFinding implements IIterableAlgorithm {
|
|||
public BlockIndex index;
|
||||
}
|
||||
|
||||
private static double distance(BlockIndex i1, BlockIndex i2) {
|
||||
return Math.sqrt(distanceSq(i1, i2));
|
||||
}
|
||||
|
||||
private static double distanceSq(BlockIndex i1, BlockIndex i2) {
|
||||
double dx = (double) i1.x - (double) i2.x;
|
||||
double dy = (double) i1.y - (double) i2.y;
|
||||
|
@ -219,17 +199,11 @@ public class PathFinding implements IIterableAlgorithm {
|
|||
}
|
||||
|
||||
private boolean endReached(int x, int y, int z) {
|
||||
if (zone != null && !zone.contains(x, y, z)) {
|
||||
return false;
|
||||
} else if (pathFound != null) {
|
||||
return pathFound.matches(world, x, y, z);
|
||||
if (maxDistanceToEndSq == 0) {
|
||||
return end.x == x && end.y == y && end.z == z;
|
||||
} else {
|
||||
if (maxDistanceToEndSq == 0) {
|
||||
return end.x == x && end.y == y && end.z == z;
|
||||
} else {
|
||||
return BuildCraftAPI.isSoftBlock(world, x, y, z)
|
||||
&& distanceSq(new BlockIndex(x, y, z), end) <= maxDistanceToEndSq;
|
||||
}
|
||||
return BuildCraftAPI.isSoftBlock(world, x, y, z)
|
||||
&& distanceSq(new BlockIndex(x, y, z), end) <= maxDistanceToEndSq;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ public class AIRobotGotoBlock extends AIRobotGoto {
|
|||
}
|
||||
|
||||
public AIRobotGotoBlock(EntityRobotBase robot, LinkedList<BlockIndex> iPath) {
|
||||
super(robot);
|
||||
this(robot);
|
||||
path = iPath;
|
||||
finalX = path.getLast().x;
|
||||
finalY = path.getLast().y;
|
||||
|
|
|
@ -29,10 +29,10 @@ public class AIRobotSearchBlock extends AIRobot {
|
|||
super(iRobot);
|
||||
|
||||
pathFound = iPathFound;
|
||||
zone = iRobot.getZoneToWork();
|
||||
if (!random) {
|
||||
blockIter = new BlockScannerExpanding().iterator();
|
||||
} else {
|
||||
zone = iRobot.getZoneToWork();
|
||||
if (zone != null) {
|
||||
BlockIndex pos = new BlockIndex(iRobot);
|
||||
blockIter = new BlockScannerZoneRandom(pos.x, pos.y, pos.z, iRobot.worldObj.rand, zone)
|
||||
|
|
Loading…
Reference in a new issue