public static Vec2i spitballRoom(Random rand,VectorField<DungeonTile> dungeon,int x,int y,int minSize,int maxSize,final DungeonTile material){
  int sizeDelta=maxSize - minSize;
  int x1=x;
  int y1=y;
  int x2=x;
  int y2=y;
  int len=rand.nextInt(sizeDelta) + minSize;
  int breadth=len - (len / 4);
  if (breadth < minSize)   breadth=minSize;
  if (rand.nextBoolean()) {
    int tmp=len;
    len=breadth;
    breadth=tmp;
  }
  int halfBreadth=breadth / 2;
  int dir=rand.nextInt(4);
switch (dir) {
case 0:
    x2=x1 + len;
  y1-=halfBreadth;
y2+=halfBreadth;
break;
case 1:
y2=y1 + len;
x1-=halfBreadth;
x2+=halfBreadth;
break;
case 2:
x2=x1 - len;
y1-=halfBreadth;
y2+=halfBreadth;
break;
default :
case 3:
y2=y1 - len;
x1-=halfBreadth;
x2+=halfBreadth;
break;
}
if (!dungeon.isInBounds(x1,y1) || !dungeon.isInBounds(x2,y2)) {
return null;
}
int width=Math.abs(x2 - x1) + 1;
int height=Math.abs(y2 - y1) + 1;
final MutableCollisionResult collision=new MutableCollisionResult();
dungeon.visitRect(x1,y1,width,height,null);
if (collision.result) {
return null;
}
dungeon.visitRect(x1,y1,width,height,null);
Vec2i result=new Vec2i(x,y);
int dir2=rand.nextInt(3);
if (dir2 >= dir) dir2++;
switch (dir2) {
case 0:
result.x=x1;
result.y=y1 + (height / 2) + 1;
break;
case 1:
result.y=y1;
result.x=x1 + (width / 2) + 1;
break;
case 2:
result.x=x2;
result.y=y1 + (height / 2) + 1;
break;
default :
case 3:
result.y=y2;
result.x=x1 + (width / 2) + 1;
break;
}
return result;
}

public static Vec2i spitballRoom ( Random rand , VectorField < DungeonTile > dungeon , int x , int y , int minSize , int maxSize , final DungeonTile material ) { int sizeDelta = maxSize - minSize ; int x1 = x ; int y1 = y ; int x2 = x ; int y2 = y ; int len = rand . nextInt ( sizeDelta ) + minSize ; int breadth = len - ( len / 4 ) ; if ( breadth < minSize ) breadth = minSize ; if ( rand . nextBoolean ( ) ) { int tmp = len ; len = breadth ; breadth = tmp ; } int halfBreadth = breadth / 2 ; int dir = rand . nextInt ( 4 ) ; switch ( dir ) { case 0 : x2 = x1 + len ; y1 -= halfBreadth ; y2 += halfBreadth ; break ; case 1 : y2 = y1 + len ; x1 -= halfBreadth ; x2 += halfBreadth ; break ; case 2 : x2 = x1 - len ; y1 -= halfBreadth ; y2 += halfBreadth ; break ; default : case 3 : y2 = y1 - len ; x1 -= halfBreadth ; x2 += halfBreadth ; break ; } if ( ! dungeon . isInBounds ( x1 , y1 ) || ! dungeon . isInBounds ( x2 , y2 ) ) { return null ; } int width = Math . abs ( x2 - x1 ) + 1 ; int height = Math . abs ( y2 - y1 ) + 1 ; final MutableCollisionResult collision = new MutableCollisionResult ( ) ; dungeon . visitRect ( x1 , y1 , width , height , null ) ; if ( collision . result ) { return null ; } dungeon . visitRect ( x1 , y1 , width , height , null ) ; Vec2i result = new Vec2i ( x , y ) ; int dir2 = rand . nextInt ( 3 ) ; if ( dir2 >= dir ) dir2 ++ ; switch ( dir2 ) { case 0 : result . x = x1 ; result . y = y1 + ( height / 2 ) + 1 ; break ; case 1 : result . y = y1 ; result . x = x1 + ( width / 2 ) + 1 ; break ; case 2 : result . x = x2 ; result . y = y1 + ( height / 2 ) + 1 ; break ; default : case 3 : result . y = y2 ; result . x = x1 + ( width / 2 ) + 1 ; break ; } return result ; }
turn a 1 - square node into a room
