v0.6.0: significant builder improvements
This commit is contained in:
parent
04ca594c13
commit
e4340f6434
|
@ -33,8 +33,8 @@ import com.shatteredpixel.shatteredpixeldungeon.items.Item;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.items.potions.Potion;
|
import com.shatteredpixel.shatteredpixeldungeon.items.potions.Potion;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.items.rings.RingOfWealth;
|
import com.shatteredpixel.shatteredpixeldungeon.items.rings.RingOfWealth;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.Scroll;
|
import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.Scroll;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.levels.builders.BranchesBuilder;
|
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.levels.builders.Builder;
|
import com.shatteredpixel.shatteredpixeldungeon.levels.builders.Builder;
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.levels.builders.LoopBuilder;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.levels.painters.Painter;
|
import com.shatteredpixel.shatteredpixeldungeon.levels.painters.Painter;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room;
|
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.PitRoom;
|
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.PitRoom;
|
||||||
|
@ -125,8 +125,10 @@ public abstract class RegularLevel extends Level {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Builder builder(){
|
protected Builder builder(){
|
||||||
//TODO need a much better builder here
|
return new LoopBuilder()
|
||||||
return new BranchesBuilder();
|
.setLoopShape( 2 ,
|
||||||
|
Random.Float(0.6f, 0.9f),
|
||||||
|
Random.Int(4) == 0 ? 0.25f : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract Painter painter();
|
protected abstract Painter painter();
|
||||||
|
|
|
@ -31,7 +31,6 @@ import com.shatteredpixel.shatteredpixeldungeon.items.Item;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.levels.builders.Builder;
|
import com.shatteredpixel.shatteredpixeldungeon.levels.builders.Builder;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.levels.builders.LoopBuilder;
|
import com.shatteredpixel.shatteredpixeldungeon.levels.builders.LoopBuilder;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room;
|
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.connection.TunnelRoom;
|
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.RatKingRoom;
|
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.RatKingRoom;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.EmptyRoom;
|
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.EmptyRoom;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.SewerBossEntranceRoom;
|
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.SewerBossEntranceRoom;
|
||||||
|
@ -59,10 +58,7 @@ public class SewerBossLevel extends SewerLevel {
|
||||||
int standards = standardRooms();
|
int standards = standardRooms();
|
||||||
for (int i = 0; i < standards; i++) {
|
for (int i = 0; i < standards; i++) {
|
||||||
initRooms.add(new EmptyRoom());
|
initRooms.add(new EmptyRoom());
|
||||||
initRooms.add(new TunnelRoom());
|
|
||||||
}
|
}
|
||||||
initRooms.add(new TunnelRoom());
|
|
||||||
if (Random.Int(3) == 0) initRooms.add(new TunnelRoom());
|
|
||||||
|
|
||||||
initRooms.add(new RatKingRoom());
|
initRooms.add(new RatKingRoom());
|
||||||
return initRooms;
|
return initRooms;
|
||||||
|
@ -76,7 +72,7 @@ public class SewerBossLevel extends SewerLevel {
|
||||||
protected Builder builder(){
|
protected Builder builder(){
|
||||||
return new LoopBuilder()
|
return new LoopBuilder()
|
||||||
.setPathLength(1f, new float[]{1})
|
.setPathLength(1f, new float[]{1})
|
||||||
.setTunnelLength(new float[]{1}, new float[]{1});
|
.setTunnelLength(new float[]{0, 3, 1}, new float[]{1});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -30,7 +30,41 @@ import java.util.ArrayList;
|
||||||
//A builder with one core loop as its primary element
|
//A builder with one core loop as its primary element
|
||||||
public class LoopBuilder extends RegularBuilder {
|
public class LoopBuilder extends RegularBuilder {
|
||||||
|
|
||||||
//TODO customizeable equation for angle changes (currently we're just linear)
|
//These methods allow for the adjusting of the shape of the loop
|
||||||
|
//by default the loop is a perfect circle, but it can be adjusted
|
||||||
|
|
||||||
|
//increasing the exponent will increase the the curvature, making the loop more oval shaped.
|
||||||
|
private int curveExponent = 0;
|
||||||
|
|
||||||
|
//This is a percentage (range 0-1) of the intensity of the curve function
|
||||||
|
// 0 makes for a perfect linear curve (circle)
|
||||||
|
// 1 means the curve is completely determined by the curve exponent
|
||||||
|
private float curveIntensity = 1;
|
||||||
|
|
||||||
|
//Adjusts the starting point along the loop.
|
||||||
|
// a common example, setting to 0.25 will make for a short fat oval instead of a long one.
|
||||||
|
private float curveOffset = 0;
|
||||||
|
|
||||||
|
public LoopBuilder setLoopShape(int exponent, float intensity, float offset){
|
||||||
|
this.curveExponent = Math.abs(exponent);
|
||||||
|
curveIntensity = intensity % 1f;
|
||||||
|
curveOffset = offset % 0.5f;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
private float targetAngle( float percentAlong ){
|
||||||
|
percentAlong += curveOffset;
|
||||||
|
return 360f * (float)(
|
||||||
|
curveIntensity * curveEquation(percentAlong)
|
||||||
|
+ (1-curveIntensity)*(percentAlong)
|
||||||
|
- curveOffset);
|
||||||
|
}
|
||||||
|
|
||||||
|
private double curveEquation( double x ){
|
||||||
|
return Math.pow(4, 2*curveExponent)
|
||||||
|
*(Math.pow((x % 0.5f )-0.25, 2*curveExponent + 1))
|
||||||
|
+ 0.25 + 0.5*Math.floor(2*x);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ArrayList<Room> build(ArrayList<Room> rooms) {
|
public ArrayList<Room> build(ArrayList<Room> rooms) {
|
||||||
|
@ -49,14 +83,11 @@ public class LoopBuilder extends RegularBuilder {
|
||||||
ArrayList<Room> loop = new ArrayList<>();
|
ArrayList<Room> loop = new ArrayList<>();
|
||||||
int roomsOnLoop = (int)(multiConnections.size()*pathLength) + Random.chances(pathLenJitterChances);
|
int roomsOnLoop = (int)(multiConnections.size()*pathLength) + Random.chances(pathLenJitterChances);
|
||||||
roomsOnLoop = Math.min(roomsOnLoop, multiConnections.size());
|
roomsOnLoop = Math.min(roomsOnLoop, multiConnections.size());
|
||||||
if (exit != null) roomsOnLoop++;
|
|
||||||
roomsOnLoop++;
|
roomsOnLoop++;
|
||||||
|
|
||||||
for (int i = 0; i < roomsOnLoop; i++){
|
for (int i = 0; i < roomsOnLoop; i++){
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
loop.add(entrance);
|
loop.add(entrance);
|
||||||
else if (exit != null && i == roomsOnLoop/2)
|
|
||||||
loop.add(exit);
|
|
||||||
else
|
else
|
||||||
loop.add(multiConnections.remove(0));
|
loop.add(multiConnections.remove(0));
|
||||||
|
|
||||||
|
@ -66,12 +97,13 @@ public class LoopBuilder extends RegularBuilder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (exit != null) loop.add(loop.size()/2, exit);
|
||||||
|
|
||||||
Room prev = entrance;
|
Room prev = entrance;
|
||||||
float targetAngle = startAngle;
|
float targetAngle;
|
||||||
float angleChange = 360f / loop.size();
|
|
||||||
for (int i = 1; i < loop.size(); i++){
|
for (int i = 1; i < loop.size(); i++){
|
||||||
Room r = loop.get(i);
|
Room r = loop.get(i);
|
||||||
targetAngle += angleChange;
|
targetAngle = startAngle + targetAngle( i / (float)loop.size());
|
||||||
if (placeRoom(rooms, prev, r, targetAngle) != -1) {
|
if (placeRoom(rooms, prev, r, targetAngle) != -1) {
|
||||||
prev = r;
|
prev = r;
|
||||||
if (!rooms.contains(prev))
|
if (!rooms.contains(prev))
|
||||||
|
@ -87,6 +119,13 @@ public class LoopBuilder extends RegularBuilder {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (shop != null) {
|
||||||
|
float angle;
|
||||||
|
do {
|
||||||
|
angle = placeRoom(loop, entrance, shop, Random.Float(360f));
|
||||||
|
} while (angle == -1);
|
||||||
|
}
|
||||||
|
|
||||||
ArrayList<Room> branchable = new ArrayList<>(loop);
|
ArrayList<Room> branchable = new ArrayList<>(loop);
|
||||||
|
|
||||||
ArrayList<Room> roomsToBranch = new ArrayList<>();
|
ArrayList<Room> roomsToBranch = new ArrayList<>();
|
||||||
|
|
|
@ -46,9 +46,9 @@ public abstract class RegularBuilder extends Builder {
|
||||||
}
|
}
|
||||||
|
|
||||||
//path length is the percentage of pathable rooms that are on
|
//path length is the percentage of pathable rooms that are on
|
||||||
protected float pathLength = 0.1f;
|
protected float pathLength = 0.67f;
|
||||||
//The chance weights for extra rooms to be added to the path
|
//The chance weights for extra rooms to be added to the path
|
||||||
protected float[] pathLenJitterChances = new float[]{0, 2, 1};
|
protected float[] pathLenJitterChances = new float[]{1, 0, 0};
|
||||||
|
|
||||||
public RegularBuilder setPathLength( float len, float[] jitter ){
|
public RegularBuilder setPathLength( float len, float[] jitter ){
|
||||||
pathLength = len;
|
pathLength = len;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user