v0.6.0: added proper neighbour finding logic to builders
This commit is contained in:
+18
-3
@@ -39,6 +39,15 @@ public abstract class Builder {
|
|||||||
//builders take a list of rooms and returns them as a connected map
|
//builders take a list of rooms and returns them as a connected map
|
||||||
//returns null on failure
|
//returns null on failure
|
||||||
public abstract ArrayList<Room> build(ArrayList<Room> rooms);
|
public abstract ArrayList<Room> build(ArrayList<Room> rooms);
|
||||||
|
|
||||||
|
protected static void findNeighbours(ArrayList<Room> rooms){
|
||||||
|
Room[] ra = rooms.toArray( new Room[0] );
|
||||||
|
for (int i=0; i < ra.length-1; i++) {
|
||||||
|
for (int j=i+1; j < ra.length; j++) {
|
||||||
|
ra[i].addNeigbour( ra[j] );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//returns a rectangle representing the maximum amount of free space from a specific start point
|
//returns a rectangle representing the maximum amount of free space from a specific start point
|
||||||
protected static Rect findFreeSpace(Point start, ArrayList<Room> collision, int maxSize){
|
protected static Rect findFreeSpace(Point start, ArrayList<Room> collision, int maxSize){
|
||||||
@@ -125,6 +134,14 @@ public abstract class Builder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static final double A = 180 / Math.PI;
|
private static final double A = 180 / Math.PI;
|
||||||
|
|
||||||
|
//returns the angle in degrees made by the centerpoints of 2 rooms, with 0 being straight up.
|
||||||
|
protected static float angleBetweenRooms( Room from, Room to){
|
||||||
|
PointF fromCenter = new PointF((from.left + from.right)/2f, (from.top + from.bottom)/2f);
|
||||||
|
PointF toCenter = new PointF((to.left + to.right)/2f, (to.top + to.bottom)/2f);
|
||||||
|
double m = (toCenter.y - fromCenter.y)/(toCenter.x - fromCenter.x);
|
||||||
|
return (float)(A*(Math.atan(m) + Math.PI/2f));
|
||||||
|
}
|
||||||
|
|
||||||
//Attempts to place a room such that the angle between the center of the previous room
|
//Attempts to place a room such that the angle between the center of the previous room
|
||||||
// and it matches the given angle ([0-360), where 0 is straight up) as closely as possible.
|
// and it matches the given angle ([0-360), where 0 is straight up) as closely as possible.
|
||||||
@@ -219,9 +236,7 @@ public abstract class Builder {
|
|||||||
|
|
||||||
//attempt to connect, return the result angle if successful.
|
//attempt to connect, return the result angle if successful.
|
||||||
if (next.connect(prev)){
|
if (next.connect(prev)){
|
||||||
PointF nextCenter = new PointF((next.left + next.right)/2f, (next.top + next.bottom)/2f);
|
return angleBetweenRooms(prev, next);
|
||||||
double trueM = (nextCenter.y - prevCenter.y)/(nextCenter.x - prevCenter.x);
|
|
||||||
return (float)(A*(Math.atan(trueM) + Math.PI/2f));
|
|
||||||
} else {
|
} else {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|||||||
+19
-3
@@ -26,9 +26,7 @@ import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.ShopRoom;
|
|||||||
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.EntranceRoom;
|
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.EntranceRoom;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.ExitRoom;
|
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.ExitRoom;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.tunnel.TunnelRoom;
|
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.tunnel.TunnelRoom;
|
||||||
import com.watabou.utils.Point;
|
|
||||||
import com.watabou.utils.Random;
|
import com.watabou.utils.Random;
|
||||||
import com.watabou.utils.Rect;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
@@ -42,7 +40,7 @@ public class LineBuilder extends Builder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
//path length is a percentage of total path rooms
|
//path length is the percentage of pathable rooms that are on the path
|
||||||
private float pathLength = 0.2f;
|
private float pathLength = 0.2f;
|
||||||
//The chance weights for extra rooms to be added to the path
|
//The chance weights for extra rooms to be added to the path
|
||||||
private float[] pathLenJitterChances = new float[]{1, 1};
|
private float[] pathLenJitterChances = new float[]{1, 1};
|
||||||
@@ -61,6 +59,13 @@ public class LineBuilder extends Builder {
|
|||||||
branchTunnelChances = branch;
|
branchTunnelChances = branch;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private float extraConnectionChance = 0.1f;
|
||||||
|
|
||||||
|
public LineBuilder setExtraConnectionChance( float chance ){
|
||||||
|
extraConnectionChance = chance;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ArrayList<Room> build(ArrayList<Room> rooms) {
|
public ArrayList<Room> build(ArrayList<Room> rooms) {
|
||||||
@@ -174,6 +179,17 @@ public class LineBuilder extends Builder {
|
|||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
findNeighbours(rooms);
|
||||||
|
|
||||||
|
for (Room r : rooms){
|
||||||
|
for (Room n : r.neigbours){
|
||||||
|
if (!n.connected.containsKey(r)
|
||||||
|
&& Random.Float() < extraConnectionChance){
|
||||||
|
r.connect(n);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return rooms;
|
return rooms;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user