v0.6.0: implemented point connection limits for rooms
This commit is contained in:
parent
9a902d97bd
commit
7153104e4d
|
@ -21,7 +21,7 @@
|
|||
|
||||
package com.watabou.utils;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Rect {
|
||||
|
||||
|
@ -133,8 +133,8 @@ public class Rect {
|
|||
return shrink( 1 );
|
||||
}
|
||||
|
||||
public HashSet<Point> getPoints() {
|
||||
HashSet<Point> points = new HashSet<>(square()*2);
|
||||
public ArrayList<Point> getPoints() {
|
||||
ArrayList<Point> points = new ArrayList<>(square()*2);
|
||||
for (int i = left; i <= right; i++)
|
||||
for (int j = top; j <= bottom; j++)
|
||||
points.add(new Point(i, j));
|
||||
|
|
|
@ -29,6 +29,7 @@ import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room;
|
|||
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.StandardRoom;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.levels.traps.Trap;
|
||||
import com.watabou.utils.PathFinder;
|
||||
import com.watabou.utils.Point;
|
||||
import com.watabou.utils.Random;
|
||||
import com.watabou.utils.Rect;
|
||||
|
||||
|
@ -113,15 +114,12 @@ public class RegularPainter extends Painter {
|
|||
if (door == null) {
|
||||
|
||||
Rect i = r.intersect( n );
|
||||
if (i.width() == 0) {
|
||||
door = new Room.Door(
|
||||
i.left,
|
||||
Random.Int( i.top + 1, i.bottom ) );
|
||||
} else {
|
||||
door = new Room.Door(
|
||||
Random.Int( i.left + 1, i.right ),
|
||||
i.top);
|
||||
ArrayList<Point> doorSpots = new ArrayList<>();
|
||||
for (Point p : i.getPoints()){
|
||||
if (r.canConnect(p) && n.canConnect(p))
|
||||
doorSpots.add(p);
|
||||
}
|
||||
door = new Room.Door(Random.element(doorSpots));
|
||||
|
||||
r.connected.put( n, door );
|
||||
n.connected.put( r, door );
|
||||
|
|
|
@ -190,20 +190,38 @@ public class Room extends Rect implements Graph.Node, Bundlable {
|
|||
//TODO make abstract
|
||||
public int maxConnections(int direction){ return -1; }
|
||||
|
||||
//only considers point-specific limits, not direction limits
|
||||
public boolean canConnect(Point p){
|
||||
//point must be along exactly one edge, no corners.
|
||||
return (p.x == left || p.x == right) != (p.y == top || p.y == bottom);
|
||||
}
|
||||
|
||||
//only considers direction limits, not point-specific limits
|
||||
public boolean canConnect(int direction){
|
||||
return remConnections(direction) > 0;
|
||||
}
|
||||
|
||||
//considers both direction and point limits
|
||||
public boolean canConnect( Room r ){
|
||||
Rect i = intersect( r );
|
||||
|
||||
boolean foundPoint = false;
|
||||
for (Point p : i.getPoints()){
|
||||
if (canConnect(p) && r.canConnect(p)){
|
||||
foundPoint = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!foundPoint) return false;
|
||||
|
||||
if (i.width() == 0 && i.left == left)
|
||||
return canConnect(LEFT);
|
||||
return canConnect(LEFT) && r.canConnect(LEFT);
|
||||
else if (i.height() == 0 && i.top == top)
|
||||
return canConnect(TOP);
|
||||
return canConnect(TOP) && r.canConnect(TOP);
|
||||
else if (i.width() == 0 && i.right == right)
|
||||
return canConnect(RIGHT);
|
||||
return canConnect(RIGHT) && r.canConnect(RIGHT);
|
||||
else if (i.height() == 0 && i.bottom == bottom)
|
||||
return canConnect(BOTTOM);
|
||||
return canConnect(BOTTOM) && r.canConnect(BOTTOM);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
@ -224,7 +242,7 @@ public class Room extends Rect implements Graph.Node, Bundlable {
|
|||
|
||||
public boolean connect( Room room ) {
|
||||
if ((neigbours.contains(room) || addNeigbour(room))
|
||||
&& !connected.containsKey( room ) && canConnect(room) && room.canConnect(this)) {
|
||||
&& !connected.containsKey( room ) && canConnect(room)) {
|
||||
connected.put( room, null );
|
||||
room.connected.put( this, null );
|
||||
return true;
|
||||
|
@ -288,6 +306,10 @@ public class Room extends Rect implements Graph.Node, Bundlable {
|
|||
}
|
||||
public Type type = Type.EMPTY;
|
||||
|
||||
public Door( Point p ){
|
||||
super(p);
|
||||
}
|
||||
|
||||
public Door( int x, int y ) {
|
||||
super( x, y );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user