wall half closure control + layers

- add onewaywall option to create a wall if there is not step back
- add layers of maze
- load minetest scheme .we with onewall option
This commit is contained in:
philippe lhardy
2020-11-05 19:50:42 +01:00
parent 52a2d3f1e3
commit bf918333bf
5 changed files with 90 additions and 20 deletions

View File

@@ -85,6 +85,8 @@ public class LabyModel implements WallsProvider {
MazeCreationListener listener = null;
// do we create wall when only one way is possible ?
private boolean onewaywall = false;
private LabyModel(int width, int height, int maxdepth, Random random) {
this.width = width;
@@ -713,17 +715,23 @@ public class LabyModel implements WallsProvider {
int reversedirection = 0;
// is this direction on the path ? yes => no wall
if ((t[x][y] & direction) == direction) {
return false;
if ( isFlagSet(t[x][y], direction)) {
if (!onewaywall) {
return false;
}
// onewaywall : should check reverse direction is ok too.
}
else
{
if (onewaywall)
{
return true;
}
}
// is adjacent tile in direction pointing in reverse direction ? yes =>
// no wall
if ((direction & POSITIVE) == POSITIVE) {
delta = 1;
} else {
delta = -1;
}
delta = ((direction & POSITIVE) == POSITIVE) ? 1 : -1;
if ((direction & HORIZONTAL) == HORIZONTAL) {
newx = x + delta;
@@ -736,7 +744,7 @@ public class LabyModel implements WallsProvider {
}
if ((newx >= 0) && (newy >= 0) && (newx < width) && (newy < height)) {
return !isFlagSet(t[newx][newy], (short) reversedirection);
return ! isFlagSet(t[newx][newy], (short) reversedirection);
} else {
// outside boundaries.
// TODO CHECK exits.
@@ -744,13 +752,16 @@ public class LabyModel implements WallsProvider {
}
}
public void setOnewaywall(boolean onewaywall) {
this.onewaywall = onewaywall;
}
/**
* is there no wall in that direction ?
**/
public boolean canMoveInDirection(int x, int y, short direction) {
// tried to replace by but does not work ( can't go back ...).
// return ! hasWallInDirection(x,y, (short) (direction << FLAGLENGTH));
return ((getWalls(x, y) & direction ) == 0);
// one way wall will create walll if it not possible to step back to current position from next position
return onewaywall ? ( ! hasWallInDirection(x,y, (short) (direction << FLAGLENGTH)) ) : ((getWalls(x, y) & direction ) == 0);
}
}